Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / December 2003

Tip: Looking for answers? Try searching our database.

'$' in C identifiers?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SaGS - 24 Dec 2003 09:20 GMT
Hi all,

Either I'm missing something big here, or there's a problem with the C
compiler in .NET 2003; and with the C compiler in Visual Studio 6 SP5 too
...

Consider the following 2 lines:

       #define TEST_$$$  0x05
       static test_$$$[] = { TEST_$$$ };

The compiler works as if '$' were a valid character to be used for an
identifier, and signals no warnings/errors.

From what I know, during preprocessing it should define the symbol "TEST_"
as the token sequence "$" "$" "$" "0x05" (I put the quotes to mark how I
consider the source text should be broken into tokens), so the second line
becomes

   "static" "test_" "$" "$" "$" "[" "]" "=" "{" "$" "$" "$" "0x05" "$" "$"
"$" "}" ";"

(with lots of syntax errors).

What I'm missing here? Or is there a known bug with the C compiler?
Bo Persson - 25 Dec 2003 12:04 GMT
> Hi all,
>
[quoted text clipped - 9 lines]
> The compiler works as if '$' were a valid character to be used for an
> identifier, and signals no warnings/errors.

Dollar signs are not allowed at all in a C/C++ program. It is not defined
what happens if it is present anyway.

Bo Persson
SaGS - 26 Dec 2003 04:00 GMT
> > Hi all,
> >
[quoted text clipped - 11 lines]
>
> Dollar signs are not allowed at all in a C/C++ program.

Yes, I agree.

> It is not defined
> what happens if it is present anyway.

Actually, the preprocessor grammar says that any non-whitespace character
that is not part of an reserved word/ identifier/ operator/ etc is
considered a separate token. And, should'n the compiler give an error if it
finds invalid characters?

> Bo Persson

Merry Christmas to all!
Bo Persson - 26 Dec 2003 09:37 GMT
> > > Hi all,
> > >
[quoted text clipped - 21 lines]
> that is not part of an reserved word/ identifier/ operator/ etc is
> considered a separate token.

Technically the dollar isn't even recognized as a character...

>And, should'n the compiler give an error if it
> finds invalid characters?

It does, if you select "Disable Language Extensions". Seems like allowing $
is yet another MS extension!

Bo Persson
SaGS - 28 Dec 2003 04:10 GMT
> ...
> It does, if you select "Disable Language Extensions". Seems like allowing $
> is yet another MS extension!
> ...

Yes, you're right here. What irritates me is that I haven't found this
documented; maybe it's an "unintended MS extension" (= bug)!

Further investigation shows a little mess about invalid characters. From the
C/C++ perspective, "@" and "`" (backquote) are in the same situation as "$":
these are the only characters in the source charset (7-bit ASCII) that are
not used. (Exception: "@" is used by the MS-specific preprocessor operator
"@#").

But:
(a) If they appear as-is: "@" and "`" always give "error C2018: unknown
character 'hexnumber'", while "$" gives C2018 only in ANSI mode, and is
accepted as (part of) an identifier with MS Extensions.

(b) "$" and "@" can be inserted in an identifier, even in ANSI-compatible
mode, using Unicode Character Names:

   int \u0024;

creates a variable named "$".  "`" cannot be specified with an UCN (UCN are
only accepted for extended characters, "$" and "@"; this is documented).

(c) As a side-note, error messages regarding identifiers "\u0024" and
"\u0040" refer to "operator `$'" and "operator `@'"!!!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.