cảnh báo này xuất phát từ tập tin có tên là "cccp.c" trong gcc (như các phiên bản 2,95; là tập tin này từ "nước Nga Xô Viết"?), Và nó không thể bị tắt. Vẫn không có tùy chọn để tắt riêng cảnh báo này ngay cả trong git head, gcc/libcpp/macro.c file (dòng 2527 và line 2994 cùng một tệp)
Tôi sẽ trích dẫn nguồn một chút.
2525 /* Returns nonzero if a macro redefinition warning is required. */
2526 static bool
2527 warn_of_redefinition (cpp_reader *pfile, cpp_hashnode *node,
2528 const cpp_macro *macro2)
2529 {
...
2537 /* Suppress warnings for builtins that lack the NODE_WARN flag. */
..
2545 /* Redefinitions of conditional (context-sensitive) macros, on
2546 the other hand, must be allowed silently. */
...
2550 /* Redefinition of a macro is allowed if and only if the old and new
2551 definitions are the same. (6.10.3 paragraph 2). */
...
2561 /* Check parameter spellings. */
...
2566 /* Check the replacement text or tokens. */
...
2573 for (i = 0; i < macro1->count; i++)
2574 if (!_cpp_equiv_tokens (¯o1->exp.tokens[i], ¯o2->exp.tokens[i]))
2575 return true;
Vì vậy, trong trường hợp của bạn, hàm warn_of_redefinition
sẽ trả về true. Và đây là cách sử dụng thực tế:
2989 if (node->type == NT_MACRO)
2990 {
2991 if (CPP_OPTION (pfile, warn_unused_macros))
2992 _cpp_warn_if_unused_macro (pfile, node, NULL);
2993
2994 if (warn_of_redefinition (pfile, node, macro))
2995 {
2996 const int reason = (node->flags & NODE_BUILTIN)
2997 ? CPP_W_BUILTIN_MACRO_REDEFINED : CPP_W_NONE;
2998 bool warned;
2999
3000 warned = cpp_pedwarning_with_line (pfile, reason,
3001 pfile->directive_line, 0,
3002 "\"%s\" redefined",
3003 NODE_NAME (node));
3004
3005 if (warned && node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
3006 cpp_error_with_line (pfile, CPP_DL_NOTE,
3007 node->value.macro->line, 0,
3008 "this is the location of the previous definition");
3009 }
3010 }
Vì vậy, không có tùy chọn cụ thể nào. Và câu trả lời của Greg là tốt cho trường hợp này, chỉ cần xác định lại chuỗi rỗng của bạn ngay trước khi định nghĩa lại.
Bạn có thể sử dụng '-Wp, -w' để vô hiệu hóa [cảnh báo tiền xử lý] (http://gcc.gnu.org/onlinedocs/cpp/Invocation.html#Invocation) – osgx
cảnh báo này xuất phát từ Nga Xô tệp có tên "cccp.c" trong gcc (có phiên bản 2.95) và không thể tắt được. Vẫn không có tùy chọn để tắt riêng cảnh báo này [ngay cả trong git head, gcc/libcpp/macro.c] (http://gcc.gnu.org/git/?p=gcc.git;a=blob;f= libcpp/macro.c; h = f3139590d5045b128709296d1abbb81753284f10; hb = HEAD # l2527) (và dòng 2994 của cùng một tệp) – osgx
@osgx nếu bạn đưa ra nhận xét đó một câu trả lời, tôi muốn chấp nhận nó. –