tags:

views:

334

answers:

4

i have following error

error : conflicting types for 'sprintf'
error : conflicting types for 'vsprintf'
error : conflicting types for 'vprintf'
error : conflicting types for 'select'

in my header file, the code is

extern char *sprintf(char*,const char*,... )

actually i include #include <stdio.h>

but for solaries we write as

# ifndef HPUX
extern char *sprintf(char*,const char*,... )
+2  A: 

Don't manually declare standard functions, just include <stdio.h>.

(And, if you insist on declaring them yourself, at least get the type right...)

David Gelhar
+3  A: 

Rather than declaring the functions yourself you should just include <stdio.h>. (If you are not trying to declare the well-known sprintf function from the standard library, but some custom function, you should choose a different name for your function).

Your declaration leads to a type conflict since the standard library function of the same name returns ìnt, not char*.

sth
+1  A: 

Unless you are telling the compiler to ignore standard includes (and the system C library), you probably just want to include the standard headers, i.e. as David Gelhar (the first one to answer) said.

If you are using some other C library, you would still include the standard headers, but by passing a different include path to the compiler.

You might enjoy reading up on what extern is intended to accomplish.

Tim Post
A: 

According to this Solaris man page (for Solaris DDI), <sys/ddi.h> defines sprintf as returning char *. It appears that this definition of the function is intended to be used only for device driver development. If you are not implementing a device driver, stick with the standard C version instead (which returns int) by including <stdio.h> and do not declare it again anywhere in your headers or source code.

dreamlax