CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Are dashes not allowed in function names?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

Are dashes not allowed in function names?
PostPosted: Mon Feb 04, 2013 7:35 am     Reply with quote

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: 19328

View user's profile Send private message

PostPosted: Mon Feb 04, 2013 7:46 am     Reply with quote

I don't think any mathematical operator would be allowed in a function name.
Think about it. How could the compiler parse:
Code:

   fred-harry();


Is this the variable fred, minus the function 'harry', or a function called fred-harry?.

Best Wishes
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

PostPosted: Mon Feb 04, 2013 7:58 am     Reply with quote

Ttelmah wrote:
I don't think any mathematical operator would be allowed in a function name.
Think about it. How could the compiler parse:
Code:

   fred-harry();


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 Laughing

Thanks for helping me see the reasoning.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Feb 04, 2013 9:38 am     Reply with quote

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]
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group