LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-11-2005, 01:54 PM   #1
jrtayloriv
Member
 
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 366
Blog Entries: 1

Rep: Reputation: 44
C: declaring void parameters


What does it mean when you pass type void to a C function? For instance when I say int init_module(void), does this do anything different than if I had just said int init_module()? Or, does it have some side effect that I need to know about?

thanks,
jrtayloriv
 
Old 02-11-2005, 02:03 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
As far as I know, there's no difference, except for maybe old compilers didn't accept: int init_module().
 
Old 02-11-2005, 02:04 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
No side effect - normal use is to call the function like this
Code:
foo();
Don't use the "void" part. Some compilers will not like it.
 
Old 02-11-2005, 02:05 PM   #4
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
Quote:
For instance when I say int init_module(void), does this do anything different than if I had just said int init_module()?
I think that it's basically the same when you write the body a function that does not have any arguments:
int func()
{


}.

But When you have a fuction,
let's say
int func(int a)
{...................
........................
.....................
........................
...............
}

You may declare it somewhere in a code or a header file as:
int func(); //you don't say nothing about the arguments, this is legal
but i think it is wrong to use:
int func(void); //this function has arguments and this is wrong.

This is what i think. I may be wrong

Last edited by perfect_circle; 02-11-2005 at 02:07 PM.
 
Old 02-11-2005, 02:20 PM   #5
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
basically this is what i mean:
Code:
skalkoto@darkstar:~$ cat code.c
#include <stdio.h>

int main()
{
        void func(void);
        func(3);
return 0;
}

void func(int a)
{
        printf("Nothing\n");
}
skalkoto@darkstar:~$ gcc code.c
code.c: In function `main':
code.c:6: error: too many arguments to function `func'
skalkoto@darkstar:~$ cat code1.c
#include <stdio.h>

int main()
{
        void func();
        func(3);
        return 0;
}

void func(int a)
{
        printf("Nothing\n");
}
skalkoto@darkstar:~$ gcc code1.c
skalkoto@darkstar:~$ ./a.out
Nothing
skalkoto@darkstar:~$
when you declare somewhere a function func(), this means you don't say anything about it's aguments.
On the otherhand func(void) means NO ARGUMENTS

P.S. When i started learning c you could not use a function if the body of the function was in the same file but under
the calling point of the function without declaring the function above the calling piont. Nowdays gcc has not those problems.
I miss those old days, everything was so clear.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++: Trouble declaring dynamic array Hady Programming 7 11-01-2005 01:06 AM
questions about declaring functions? alaios Programming 4 07-21-2005 02:25 AM
difference between () and = when declaring variables nadroj Programming 1 06-28-2005 01:37 PM
void main(void) linuxanswer Programming 4 10-26-2003 12:37 AM
void foo(void) and void foo() lackluster Programming 9 02-15-2003 10:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration