Error while compiling macro __COPYRIGHT with gcc -
here simple echo.c source code:
#include <sys/cdefs.h> #ifndef lint __copyright( "@(#) copyright (c) 1989, 1993\n\ regents of university of california. rights reserved.\n"); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)echo.c 8.1 (berkeley) 5/31/93"; #else __rcsid("$netbsd: echo.c,v 1.7 1997/07/20 06:07:03 thorpej exp $"); #endif #endif /* not lint */ #include <stdio.h> #include <stdlib.h> #include <string.h> int main __p((int, char *[])); int main(argc, argv) int argc; char *argv[]; { /* *main code no error @ */ }
when compiling gcc 4.4.6, study errors:
echo.c:4: error: expected declaration specifiers or â...â before string constant echo.c:3: warning: info definition has no type or storage class echo.c:12: error: expected declaration specifiers or â...â before string constant echo.c:12: warning: info definition has no type or storage class
line 3 , 4 __copyright macro. line 12 __rcsid macro.
if delete these 2 macro, compiles , runs correctly.
after googling, know these 2 macros defined in sys/cdefs.h , kind of comment message.
but why won't compile in gcc?
well after going throuhg sys/cdefs.h (ubuntu 11.10), found no __copyright
or __rcsid
defination. guess these 2 macros defined in netbsd sys/cdefs.h. added them in new header file (i name "aeodefs.h") following:
#ifndef _aeodefs_h_ #define _aeodefs_h_ #include <sys/cdefs.h> #define __idstring(name,string) \ static const char name[] __attribute__((__unused__)) = string #ifndef __rcsid #define __rcsid(s) __idstring(rcsid,s) #endif #ifndef __copyright #define __copyright(s) __idstring(copyright,s) #endif #endif /* !_aeodefs_h_ */
then alter #include <sys/cdefs.h>
#include "aeodefs.h"
.
it's done!
gcc macros
No comments:
Post a Comment