View previous topic :: View next topic |
Author |
Message |
evsource
Joined: 21 Nov 2006 Posts: 129
|
Are dashes not allowed in function names? |
Posted: Mon Feb 04, 2013 7:35 am |
|
|
Surprising that I've never come across this over the years, but I just had a function referring to something with a DC-DC converter. So I named it dc-dc_...
The compiler barked at me. I changed it to an underscore and no problem.
I've found references to other programming languages (e.g. PHP) where dashes were not allowed in function names. Is this something about C I should have just known somehow? Did my professors fail me in my college years (or did I sleep through that crucial moment in time)?
Why would a dash not be allowed? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Mon Feb 04, 2013 7:46 am |
|
|
I don't think any mathematical operator would be allowed in a function name.
Think about it. How could the compiler parse:
Is this the variable fred, minus the function 'harry', or a function called fred-harry?.
Best Wishes |
|
|
evsource
Joined: 21 Nov 2006 Posts: 129
|
|
Posted: Mon Feb 04, 2013 7:58 am |
|
|
Ttelmah wrote: | I don't think any mathematical operator would be allowed in a function name.
Think about it. How could the compiler parse:
Is this the variable fred, minus the function 'harry', or a function called fred-harry?.
Best Wishes |
I guess I haven't programmed long enough to think like a compiler
Thanks for helping me see the reasoning. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Feb 04, 2013 9:38 am |
|
|
From K&R, second edition
Quote: | A.2.3 Identifiers
An identifier is a sequence of letters and digits. The first character must be a letter; the underscore _ counts as a letter. Upper and lower case letters are different. Identifiers may have any length, and for internal identifiers, at least the first 31 characters are significant; some implementations may take more characters significant. |
In other words (ANSI C):
identifier: $[_a-zA-Z][_a-zA-Z0-9]* [IdnOrType] |
|
|
|