1

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*,... )
Alok Singhal
  • 93,253
  • 21
  • 125
  • 158
ambika
  • 39
  • 2
  • 4
  • 7

4 Answers4

5

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
  • 222,467
  • 53
  • 283
  • 367
3

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
  • 27,873
  • 3
  • 67
  • 84
1

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.

Community
  • 1
  • 1
Tim Post
  • 33,371
  • 15
  • 110
  • 174
0

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.

alanc
  • 4,102
  • 21
  • 24
dreamlax
  • 93,976
  • 29
  • 161
  • 209
  • Yes, the section 9f man pages like that are for functions defined in the kernel itself, not in the user-space libraries that programs can link with. – alanc Aug 18 '12 at 06:09