Forum > General

widechar literals

(1/3) > >>

440bx:
Hello,

I found an interesting comment in one of FPC's API definition files, specifically:
--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// L'xx' translates to 'xx'#$0000 because that forces a wide literal in FPC.That got my attention because I didn't know that.  I searched for that "feature" to be documented somewhere and, unless I missed it, it doesn't seem to be documented anywhere.

My question is: is what that comment states true ? (since it does not seem to be documented, I would like to have confirmation)

If someone knows where that detail is documented, I'd appreciate a pointer to it.

Thank you for your help.

AlexTP:
Strange, the source is L'xx' == 2 chars, but the output is 'xx' plus the null-char == 3 chars.

440bx:

--- Quote from: AlexTP on April 30, 2022, 01:29:10 pm ---Strange, the source is L'xx' == 2 chars, but the output is 'xx' plus the null-char == 3 chars.

--- End quote ---
Yes, and, if the comment is true then the output/interpretation should be 3 widechars.


marcov:
Any widechar concatination is enough, #0000 is nothing special.

e.g.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const yy = widechar('x')+'rest';
has length 5, prints xrest using an unicode routine:


--- Code: --- call fpc_write_text_unicodestr

--- End code ---

440bx:
if the compiler is considering the constant to be made of widechar(s) then I don't see how the following sample program can compile:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program _WidecharLiteral; function Test(p : pchar) : char;begin  result := p^;end; const  AWIDECHAR = widechar('x') + 'morecharacters';       { supposedly a widechar literal } begin  Test(AWIDECHAR);  { the compiler should refuse this but, it doesn't }end.                    if the constant is truly wide then the call to "Test" shouldn't compile. 

Am I missing something ?

Navigation

[0] Message Index

[#] Next page

Go to full version