Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

n3odymium

c/c++ void arguments

This topic is 5537 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, and thank you for reading my post. As I read other peoples code, I have a few questions about some function prototypes I''ve seen. One thing thats been bugging me are functions in C and C++ that go something like this: ############################################# void functionName(void) { // code code code } ############################################# the type of the function is void, but it also has ''void'' as its arguments. What gives? How does it create its function signature without arguments? What would a function like this DO? I see this style used all the time in OpenGL, but they use the typedef GLvoid instead. any insight/examples would be much appreciated. Thanks ~stu

Share this post


Link to post
Share on other sites
Advertisement
Ah, yes. The 'void' in the parentheses is optional. In this case, the function takes no arguments and acts as a 'subroutine'. So...


      
void my_function(void);


...is a function that returns nothing, and takes no arguments, but still does something.

[edited by - light-nexus on April 20, 2003 3:17:33 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by n3odymium
ah, I see. optional void within the parenthesis, eh?



means that void my_function(void); is the same as void my_function();

Share this post


Link to post
Share on other sites
By using void in the parameter list you are explicity declaring that the function takes no parameters - this makes things a little clearer for ppl reading your code.

Share this post


Link to post
Share on other sites
This is interesting; how does this add clarity for you?

I recently stopped using void in the parameter list because it was added typing overhead/just something else do change when a function changed.

If there is a benefit for some people, I would consider switching back.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Spudder
By using void in the parameter list you are explicity declaring that the function takes no parameters - this makes things a little clearer for ppl reading your code.


u no what else adds clarity? using the hole word wen ur typing ;-)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
There are some situations with some compilers where the "void" in the parameter list is required.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!