Short code for exemple:
#include <stdio.h>
int main(int * argc, char * argv[]) {
char *buf[1024];
if ((snprintf(buf,1024,"string : %s string2 : %s",argv[1],argv[2])) == -1) {
fprintf(stderr,"main : error while snprintf() \n");
exit(1);
}
fprintf(stdout,"buf = %s\n",buf);
return 0;
}
gcc -Wall -ansi -pedantic -O -g main.c -o proggy
Errors from gcc: snprintf() implicitly defined.
I then add to the source:
extern int snprintf(char *, int, const char *, ...);
I compile it again with same flags, and gcc takes it.
But when I in LINUX RH6.1 run lclint I get a parse error with:
extern int snprintf(char *, int, const char *, ...);
I know that snprintf() is not ANSI, but when I
#define _BSD_SOURCE it gets through gcc without problem,
but lclint still talks about undefined function.
I do not want to use #define _BSD_SOURCE or #define _GNU_SOURCE
I just want to explicitly declare:
extern int snprintf(char *, int, const char *, ...);
Is lclint buggy or am I missing something here?
Very, very thankfull for help. By defining the non ANSI functions myself
I can keep track of them if I would like to port the program.
Thanks in advance,
/Efraim
--
Remove nospam from my adress to reply.
--
comp.lang.c.moderated - moderation address: cl...@plethora.net
> Hi!
>
> Short code for exemple:
>
> #include <stdio.h>
> int main(int * argc, char * argv[]) {
How come gcc does not complain about the type of argc? It should be
int.
> char *buf[1024];
Should be "char buf[1024]", I suppose
> extern int snprintf(char *, int, const char *, ...);
The second argument to snprintf() is of type size_t, not int.
Any self-respectiung lint should complain that argc is not used in
your program.
Does it help if you fix those things?
By the way, just -Wall -pedantic -ansi might not be strict enough
(-Wall is a misnomer). You might want to use
-W \
-pedantic \
-Wall \
-Wtraditional \
-Wshadow \
-Wid-clash-32 \
-Wpointer-arith \
-Wcast-qual \
-Wcast-align \
-Wconversion \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wnested-externs \
to get more warnings and an approximation to a lint with gcc.
--
Oleg Goldshmidt <ogo...@NOSPAM.netvision.net.il>
"... We work by wit, and not by witchcraft;
And wit depends on dilatory time." [Shakespeare]
>Hi!
>
>Short code for exemple:
>
>#include <stdio.h>
>int main(int * argc, char * argv[]) {
> char *buf[1024];
> if ((snprintf(buf,1024,"string : %s string2 : %s",argv[1],argv[2])) == -1) {
> fprintf(stderr,"main : error while snprintf() \n");
> exit(1);
> }
> fprintf(stdout,"buf = %s\n",buf);
> return 0;
>}
>
>gcc -Wall -ansi -pedantic -O -g main.c -o proggy
>
>Errors from gcc: snprintf() implicitly defined.
>
>I then add to the source:
>
>extern int snprintf(char *, int, const char *, ...);
>
>I compile it again with same flags, and gcc takes it.
>
>But when I in LINUX RH6.1 run lclint I get a parse error with:
>
>extern int snprintf(char *, int, const char *, ...);
>
>I know that snprintf() is not ANSI, but when I
>#define _BSD_SOURCE it gets through gcc without problem,
>but lclint still talks about undefined function.
>
>I do not want to use #define _BSD_SOURCE or #define _GNU_SOURCE
>I just want to explicitly declare:
>
>extern int snprintf(char *, int, const char *, ...);
>
>Is lclint buggy or am I missing something here?
>
>Very, very thankfull for help. By defining the non ANSI functions myself
>I can keep track of them if I would like to port the program.
>
>Thanks in advance,
>
>/Efraim
>
>--
>Remove nospam from my adress to reply.
>--
>comp.lang.c.moderated - moderation address: cl...@plethora.net
#include <stdarg.h>
Florian
Tnx, will try that!
/Efraim