What is the difference between f(...), f(void) and f()


 
Thread Tools Search this Thread
Top Forums Programming What is the difference between f(...), f(void) and f()
# 1  
Old 04-28-2008
What is the difference between f(...), f(void) and f()

What is the difference between f(...) , f(void),f()
I know that f(void) doesn't take any parameters, but what about f() and f(...) Does the last call of function even exists?
# 2  
Old 04-28-2008
Quote:
Originally Posted by purplelightspar
What is the difference between f(...) , f(void),f()
I know that f(void) doesn't take any parameters, but what about f() and f(...) Does the last call of function even exists?
f(void) means that the function does not take any arguments.
f() and f(void) are synonymous since f() is the K&R C equivalent of the ANSI C f(void).
f(...) means that the function takes a variable length argument list
# 3  
Old 04-29-2008
C99 is different from K&R foo() essentially means it takes undefined arguments.
cc -Ae means compile according to strict ANSI C99 standards..
Code:
csadev:/home/jmcnama> cc -Ae foo.c
csadev:/home/jmcnama> a.out
you found foo
you found foo
you found foo
you found foo
csadev:/home/jmcnama> lint foo.c


==============
name declared but never used or defined
    __bufendtab         stdio.h(744)
    errno       errno.h(39)
    ___sysconf          signal.h(207)
    __nl_char_size      stdlib.h(79)
    sigwait     signal.h(232)
    pthread_sigmask     signal.h(234)
    pthread_kill        signal.h(235)
    getdate_err         time.h(741)
    __iob       stdio.h(174)
function used with a variable number of arguments
    foo         foo.c(4) :: foo.c(12)
    foo         foo.c(4) :: foo.c(13)
    foo         foo.c(4) :: foo.c(14)
function returns value which is sometimes ignored
    foo

It fails to lint which should be a big clue this is bad.

Here is the code:
Code:
/* C99-(semi)compliant but perverse coding */
#include <stdlib.h>

int foo()
{
	return printf("you found foo\n");
}

int main()
{
	foo();
	foo(2);
	foo("hi there");
	return foo("this code stinks");
}

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Malloc to void pointer fails

I have a function to which I will pass a struct ID and it will return me a string. I will pass a pointer to store the name string and that pointer will be allocated memory by the function called. int ConvertIDToName(void *id, void *name, size_t *size) { int status = 0; ... (5 Replies)
Discussion started by: rupeshkp728
5 Replies

2. Programming

Parameter passing to function with void * as Argument

Earlier I had one structure C typedef struct c { int cc; }CS; I used to call a library function say int GetData(CS *x) which was returning me the above structure C with data. GetData(CS *x) Function call used to be like: CS CSobj; GetData(&CSObj); Now there are two... (12 Replies)
Discussion started by: rupeshkp728
12 Replies

3. Programming

void pointer

hi guys! Is there such a thing as double void pointer dynamic allocation? And if so is it something like this? int n; void** a; a=malloc(n*sizeof(void*)); (12 Replies)
Discussion started by: vlm
12 Replies

4. HP-UX

converting void pointer to pthread_t on HPUX Itanium

i am trying to convert void pointer to pthread_t on hpux-itanium 64 bit which fails as below "src/file.cpp", line 88: error #2171: invalid type conversion pthread_t tid = reinterpret_cast<pthread_t>(m_threadId); 1 error detected in the compilation of "src/file.cpp" ... (0 Replies)
Discussion started by: skyineyes
0 Replies

5. Shell Programming and Scripting

Eliminate double void line

Hi, I need to eliminate each second void line in a text file. novus MILLENNIO ineo frater in episcopatus , presbyter et diacon|diaconus , (1 Reply)
Discussion started by: mjomba
1 Replies

6. Programming

functions that manipulate void pointers

I have two or more linked lists that have the same names for their "next". For example, struct server_t { sockaddr_in * sin; server_t * next_; } struct player_t { char name; player_t * next_; } How can I get a function to take in either type and manipulate the pointers? I... (3 Replies)
Discussion started by: pyramation
3 Replies

7. UNIX for Dummies Questions & Answers

void (char *asd)

void asdf(char *asd) is this thing a pointer? (1 Reply)
Discussion started by: khestoi
1 Replies

8. Programming

How to return void function pointer

Hello all im trying to build function that will return void function pointer what is mean is ( not working ) the main function void * myClass::getFunction(int type){ if(type==1) return &myClass::Test1; if(type==2) return &myClass::Test2; } void myClass::Test1(){... (1 Reply)
Discussion started by: umen
1 Replies

9. Shell Programming and Scripting

Sorting the Void File in CSH

First and foremost, this is not a homework for your information. I'm just new to using c-shell programming and I just wanted to make my life easier @ work. Say, the file contains the following: ID FILE NO. SL VP 1 1 22 33 1 2 ... (3 Replies)
Discussion started by: ilak1008
3 Replies
Login or Register to Ask a Question