Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-18-2005, 09:31 PM   #1
Registered: Jul 2003
Location: Osaka, Japan
Distribution: Arch, Ubuntu
Posts: 421

Rep: Reputation: 31
difference between function declaration: func() and func(void)

What is the difference between these two function declarations in C?

1) void func1();
2) void func2(void);

In a book I am reading, it says that in the first case, the compiler doesn't check the argument list passed to func1(); whereas in the second case func2() is explicitly declared to take no arguments.

I understand what that means but in real life how can the first case be useful?

Old 11-18-2005, 11:04 PM   #2
Senior Member
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
I don't think there is a difference.
Old 11-19-2005, 02:15 AM   #3
Registered: Nov 2005
Location: Coimbatore,India
Distribution: Fedora Core4
Posts: 68

Rep: Reputation: 15
Re: difference between function declaration: func() and func(void)

Originally posted by koyi
the compiler doesn't check the argument list passed to func1()
Do u mean that call such as this wouldn't raise errors-
Old 11-19-2005, 10:54 AM   #4
Registered: Jul 2003
Location: Osaka, Japan
Distribution: Arch, Ubuntu
Posts: 421

Original Poster
Rep: Reputation: 31
Alright I have tested it with this piece of simple source code.

#include <stdio.h>

int func1();
int func2(void);

int main(int argc, char **argv) {

        int a, b;

        a = func1(1, 1, 2);
        b = func2();

        printf("a = %d\tb = %d\n", a, b);

        return 0;


int func1(int a, int b) {
        return a + b;

int func2(void) {
        return 3;
And this compiles cleanly and ran with the output:

a = 2   b = 3
As you can see, in the declaration func1() is declared as just func1().
In main(), it is called with 3 arguments but in the definition of func1() it only needs two of them.
But no errors occur in both the compilation and execution.
Well, I don't think this is a bug in the compiler or what but I am just wondering how can this be useful in real life.

Btw, if you pass any arguments to func2() the an error will occur when you try to compile it.
Old 11-19-2005, 11:19 AM   #5
Senior Member
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
The declaration funct1() is actually funct1(...). main and printf are also declared that way as well. Specificly, the declarations are main(...) and printf(char *format,...). funct1(void) forces no arguments, as your book says.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to find datatype of i in func(void *i,...) kapsikum Programming 2 03-09-2005 10:07 AM
C++ prototyped func with default values ? Bluesuperman Programming 3 02-03-2005 10:20 AM
func to store strs's jnusa Programming 2 11-09-2004 05:29 AM
func. system() ---> perl vs. c rocknix Programming 1 10-17-2003 07:27 AM
ide_dma_timeout func only: 14 MesS Linux - Software 5 10-09-2001 06:37 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:55 AM.

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