gpt4 book ai didi

c - 我的编译器说这个东西 __attribute__ 是错误的,语法错误

转载 作者:太空宇宙 更新时间:2023-11-04 03:54:38 25 4
gpt4 key购买 nike

以下是 GNU m4 源代码中名为 lib/verror.h 的文件:

/* Declaration for va_list error-reporting function
Copyright (C) 2006-2007, 2009-2011 Free Software Foundation, Inc.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */

#ifndef _VERROR_H
#define _VERROR_H 1

#include "error.h"
#include <stdarg.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Print a message with `vfprintf (stderr, FORMAT, ARGS)';
if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
If STATUS is nonzero, terminate the program with `exit (STATUS)'.
Use the globals error_print_progname and error_message_count similarly
to error(). */

extern void verror (int __status, int __errnum, const char *__format,
va_list __args)
__attribute__ ((__format__ (__printf__, 3, 0)));

/* Print a message with `vfprintf (stderr, FORMAT, ARGS)';
if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
If STATUS is nonzero, terminate the program with `exit (STATUS)'.
If FNAME is not NULL, prepend the message with `FNAME:LINENO:'.
Use the globals error_print_progname, error_message_count, and
error_one_per_line similarly to error_at_line(). */

extern void verror_at_line (int __status, int __errnum, const char *__fname,
unsigned int __lineno, const char *__format,
va_list __args)
__attribute__ ((__format__ (__printf__, 5, 0)));

#ifdef __cplusplus
}
#endif

#endif /* verror.h */

我的编译器在那个叫做“attribute”的奇怪东西上爆炸了,我看了看在 K&R C 中查找它但找不到它。

看起来是严格的 GNUism GCC 东西而不是 C。

所以问题是如何去除这些垃圾,使代码能够被编译通过旧 Sun 服务器上的旧 C 编译器?完全相同的编译器可以构建 GNUmake 和 libiconv 和 gNU gettext 一样好,但最新的 GNU m4 看起来不可携带。

我看到的错误是:

/opt/SUNWspro/bin/cc  -I.   -D_REENTRANT -I/usr/local/include  -dy -xmemalign=8s -errfmt=error -erroff=%none -errshort=full -errwarn=%none -fns=no -ftrap=%none -xarch=v9 -xcode=pic32 -g -i -mc -Qy -v -Wl,-R/usr/local/lib -Xa -xstrconst -xtemp=/var/tmp -xunroll=1 -D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE -D_TS_ERRNO -c verror.c
"verror.h", line 35: error: syntax error before or at: __attribute__
"verror.h", line 35: warning: old-style declaration or incorrect type for: __attribute__
"verror.h", line 35: warning: syntax error: empty declaration
"verror.h", line 47: error: syntax error before or at: __attribute__
"verror.h", line 47: warning: old-style declaration or incorrect type for: __attribute__
"verror.h", line 47: error: identifier redefined: __attribute__
current : function() returning int
previous: function() returning int : "verror.h", line 35
"verror.h", line 47: warning: syntax error: empty declaration
"verror.c", line 44: error: identifier redefined: verror
current : function(int, int, pointer to const char, pointer to void) returning void
previous: function(int, int, pointer to const char, pointer to void) returning void : "verror.h", line 33
"verror.c", line 57: error: identifier redefined: verror_at_line
current : function(int, int, pointer to const char, unsigned int, pointer to const char, pointer to void) returning void
previous: function(int, int, pointer to const char, unsigned int, pointer to const char, pointer to void) returning void : "verror.h", line 44
cc: acomp failed for verror.c
gmake[3]: *** [verror.o] Error 2
gmake[3]: Leaving directory `/usr/local/build/m4-1.4.16_SunOS5.8_sparcv9.001/lib'
gmake[2]: *** [all] Error 2
gmake[2]: Leaving directory `/usr/local/build/m4-1.4.16_SunOS5.8_sparcv9.001/lib'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/usr/local/build/m4-1.4.16_SunOS5.8_sparcv9.001'
gmake: *** [all] Error 2

看起来很讨厌的东西。

最佳答案

__attribute__ 是一个 GCC 扩展,它也被 clang 和其他编译器借用了。如果您的编译器不支持使用此语法的属性,您可以通过在使用任何属性之前定义此宏来消除错误:

#define __attribute__(x)

请记住,删除属性可能会影响程序的行为。

关于c - 我的编译器说这个东西 __attribute__ 是错误的,语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17665803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com