I've seen macros like this: #define $Line #__LINE__ and I was wondering what the effect of the $ symbol has in a macro?

I have no idea what a $ sign does in a macro, if it even does something at all. As far as I know, the $ sign is not a reserved character and is not used for anything in C/C++, so I would imagine that it is a valid character to start a name with (especially at the pre-processor level). So, my guess would be that it was put there to signify that $Line is for the string literal code-line number (which is what the MACRO expands to, if you didn't know already). Is the MACRO used with or without the $ sign? If it is used with it, I'm guessing it is just that the name of the MACRO is "$Line". It's certainly weird, first time I see this.

It's used with the $ sign. This is the first time I've seen it aswell, I'll do some tests to see if it's a valid character for names.

Code like this compiles:

#define $THE_NUMBER_0 (0)

int main( )
{
	int $int1$ = $THE_NUMBER_0;

	$int1$ = 10;

	return 0;
}

But for some reason in VC++ you can't see the value of $int1$ when you move your mouse over it, but you can see it in the 'Locals' panel (while debugging). I don't know why I haven't seen this written anywhere.

I found this on HP docs (confirmed by MSDN too):

Identifiers

Identifiers are case sensitive and start with a letter (ISO Latin-1 decimal values 65-90 and 97-122), a dollar sign ($), a tilde (~), a colon (:), or an underscore (_); any additional characters can be a letter, digit (0-9), dollar sign ($), underscore (_), a tilde (~), a colon (:), or an operator symbol. Use of the dollar sign, tilde, and colon are extensions to C++.

I think the $ sign is a perfectly valid character for an identifier in C/C++, let alone a pre-processor macro.

EDIT: I still would not use the $ sign in an identifiers name, that's just too weird and any programmer reading it will automatically have doubts whether it does something special or not.

Edited 5 Years Ago by mike_2000_17: n/a

I still would not use the $ sign in an identifiers name, that's just too weird and any programmer reading it will automatically have doubts whether it does something special or not.

That's exactly what I did. :P

This question has already been answered. Start a new discussion instead.