quick C question, is $ a special character?

apac

Diamond Member
Apr 12, 2003
6,212
0
71
I'm encountering a strange error with lines written like such:

uint8_t PotM$potSetting;

where uint8_t is typedefed above, yields the following errors

/tmp/cc0twSga.s:134: Error: expected comma after symbol-name
/tmp/cc0twSga.s:134: Error: unknown opcode `potsetting'


If I remove the $ and everything before it, in this case PotM$, leaving only uint8_t potSetting, the error goes away. So is the $ character special in variable names?
 

akubi

Diamond Member
Apr 19, 2005
4,392
1
0
rofl....

only alphanumeric characters and underscores are allowed. must not start with a digit either
 

jman19

Lifer
Nov 3, 2000
11,225
664
126
Originally posted by: apac
I'm encountering a strange error with lines written like such:

uint8_t PotM$potSetting;

where uint8_t is typedefed above, yields the following errors

/tmp/cc0twSga.s:134: Error: expected comma after symbol-name
/tmp/cc0twSga.s:134: Error: unknown opcode `potsetting'


If I remove the $ and everything before it, in this case PotM$, leaving only uint8_t potSetting, the error goes away. So is the $ character special in variable names?

Not 100% sure, but I think you can only have alphanumeric characters in variable names...
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Originally posted by: akubi
rofl....

only alphanumeric characters and underscores are allowed. must not start with a digit either

Yes - learn the proper syntax for the language that you are using. Helps a lot

 

Stuxnet

Diamond Member
Jun 16, 2005
8,392
1
0
Originally posted by: EagleKeeper
Originally posted by: akubi
rofl....

only alphanumeric characters and underscores are allowed. must not start with a digit either

Yes - learn the proper syntax for the language that you are using. Helps a lot

I think that's what he was trying to do...
 

apac

Diamond Member
Apr 12, 2003
6,212
0
71
Originally posted by: EagleKeeper
Originally posted by: akubi
rofl....

only alphanumeric characters and underscores are allowed. must not start with a digit either

Yes - learn the proper syntax for the language that you are using. Helps a lot

Piss off. I'm working with a 4000 line C file generated from nesC code (modular). The generated code declares variables and functions with <module>$<interface>$<function name>, and I figured as much about the $ sign, but its hard to google the letter "C" to find C syntax.

This isn't counter-strike. If I ask a simple question, why be a jerk.


edit: thanks to the other people
 

jalaram

Lifer
Aug 14, 2000
12,920
2
81
Originally posted by: apac
Originally posted by: EagleKeeper
Originally posted by: akubi
rofl....

only alphanumeric characters and underscores are allowed. must not start with a digit either

Yes - learn the proper syntax for the language that you are using. Helps a lot

Piss off. I'm working with a 4000 line C file generated from nesC code (modular). The generated code declares variables and functions with <module>$<interface>$<function name>, and I figured as much about the $ sign, but its hard to google the letter "C" to find C syntax.

This isn't counter-strike. If I ask a simple question, why be a jerk.


edit: thanks to the other people

Your best option is to replace the '$' with '_' so that you don't lose what the code generated.

You can also google "C syntax" or similar terms for quick reference guides to C.
 

apac

Diamond Member
Apr 12, 2003
6,212
0
71
Originally posted by: jalaram
Originally posted by: apac
Originally posted by: EagleKeeper
Originally posted by: akubi
rofl....

only alphanumeric characters and underscores are allowed. must not start with a digit either

Yes - learn the proper syntax for the language that you are using. Helps a lot

Piss off. I'm working with a 4000 line C file generated from nesC code (modular). The generated code declares variables and functions with <module>$<interface>$<function name>, and I figured as much about the $ sign, but its hard to google the letter "C" to find C syntax.

This isn't counter-strike. If I ask a simple question, why be a jerk.


edit: thanks to the other people

Your best option is to replace the '$' with '_' so that you don't lose what the code generated.

You can also google "C syntax" or similar terms for quick reference guides to C.

Yeah I did that too but nothing specific came up. Unfortunately I don't have control over the generated code, or rather I'm trying to keep it as intact as possible, so I'll find a way to work around it. Thanks.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
You have an apology.


And my comment still stands; knowing the language syntax saves a lot of grief. I would have been a little more tactful if I had known that it was generated code which did not seem to be indicated.

As others did point out, you will have to due the substitutions; probably error line by line.
A mass sub could create as many problems as it solves.

The other pain will be that any work done could be lost everytime you regenerate the file.

There probably is no way that you can get to the code generator and correct the underlying problem.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Since "(nonspacechar)$(nonspacechar)" would be very unlikely to occur in normal C code, something like grep or a perl script could be used to automate the fixup process to change the $ to _

Code generators can be annoying -- the SOAP code generator we use gets the order of some interdependent class/structure definitions wrong, so we have to fix the resulting C++ code by hand whenever we add support for new or changed services.