Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Argument type with default promotion?? What's that?

Status
Not open for further replies.

svar

Programmer
Aug 12, 2001
349
GR
Anyone understands what's wrong here? Just a simple thing, define a struct and a function set returning a variable
of that struct test type.

typedef struct{float var1;
}test;

test set();

main(){
test v1;
v1=set(1.0);
}
test set(float myval){
test t1 ;
t1.var1=myval;
return t1;}

This fails to compile with:

10: conflicting types for `set'
10: an argument type that has a default promotion can't match an empty parameter name list declaration
4: previous declaration of `set
 
I'd say you're compiling your C code with a C++ compiler.

> test set();
In C++, this means
test set( void );

In C, an empty function declaration basically means any parameters (which are also unchecked as well).


Since you're really passing a float, that doesn't match.

Be more precise with your function prototype, so it matches your function definition.

--
 
No, I am using gcc(or do I need to disable C++?)

gcc -Wall vtest.c -o vtest.e
vtest.c:6: warning: return type defaults to `int'
vtest.c: In function `main':
vtest.c:9: warning: control reaches end of non-void function
vtest.c: At top level:
vtest.c:10: conflicting types for `set'
vtest.c:10: an argument type that has a default promotion can't match an empty parameter name list declaration
vtest.c:4: previous declaration of `set'
 
BTW, with the change you suggest, the code works
so the question is: Does gcc need C++ explicitly turned off
if you want plain C code(Of course you can prototype to keep both C and C++ happy)?
 
> so the question is: Does gcc need C++ explicitly turned off
No, you're doing the other correct thing, which is using -Wall in your command line

As you note, you're using a C compiler in a particularly strict mode with the -Wall flag

For maximum diagnostics, use
[tt]gcc -W -Wall -ansi -pedantic -O2 prog.c[/tt]

--
 
Some explanation added:
Default promotion in that case (in C and C++) means: convert float to double when passing an arg to a function without prototype (or with ... in parameters list).
It's one of default data type conversions (another examples is short to int or char to int). Promotion term - from shorter types to longer types...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top