Too many arguments provided to function-like macro invocation or

Source: Internet
Author: User

1, Problem 2, the solution to the problemChoose Apple LLVM 7.0 under build setting to GUN99

3. Causes of this problem

3.1. The following macro is defined in the NSException.h file

/* * Asserts to use in Objective-c method bodies */#If!defined (Nsassert)Using the Nsassert macro#Define NSASSERT5 (condition, desc, arg1, arg2, Arg3, Arg4, Arg5) __pragma_push_no_extra_arg_warnings _nsassertbody (( condition), (DESC), (arg1), (arg2), (ARG3), (ARG4), (ARG5)) __pragma_pop_no_extra_arg_warnings#Define NSASSERT4 (condition, desc, arg1, arg2, Arg3, Arg4) __pragma_push_no_extra_arg_warnings _nsassertbody (condition ), (DESC), (arg1), (arg2), (ARG3), (ARG4),0) __pragma_pop_no_extra_arg_warnings#Define NSASSERT3 (condition, desc, arg1, arg2, Arg3) __pragma_push_no_extra_arg_warnings _nsassertbody ((condition), ( DESC), (arg1), (arg2), (ARG3),0,0) __pragma_pop_no_extra_arg_warnings#Define NSASSERT2 (condition, desc, arg1, arg2) __pragma_push_no_extra_arg_warnings _nsassertbody ((condition), (DESC), ( ARG1), (ARG2),0, 0, 0) __pragma_pop_no_extra_arg_ Warnings#define NSAssert1 (condition, DESC, arg1) __ Pragma_push_no_extra_arg_warnings _nsassertbody (condition), (DESC), (arg1), 0, 0, 0, 0) __pragma_pop_no_extra_arg_ Warnings#define nsassert (condition, desc) __PRAGMA_ Push_no_extra_arg_warnings _nsassertbody (condition), (DESC), 0, 0, 0, 0,  0) __pragma_pop_no_extra_arg_warnings#endif   
//in the definition of Nsassert below, there is a # #__VA_ARGS__  #define Nsassert (     condition, desc, ...) do {__pragma_push_no_extra_arg_warnings if (! ( Condition) {nsstring *__assert_file__ = [nsstring s TRINGWITHUTF8STRING:__FILE__]; __assert_file__ = __assert_file__? __assert_file__: @ "<unknown file>"; [[nsassertionhandler Currenthandler] handlefailureinmethod:_cmd object:self file:__assert_file__ linenumber:__line__ Description: (DESC), ## __VA_ARGS__]; } __pragma_pop_no_extra_arg_warnings} while (0)  #endif             

3.2 # #__ Va_args__ 's Trace

1) # #__ va_args__ represents a macro with variable parameters

2) variable parameter macros are not officially supported by Ansi/iso C + +. Therefore, you should check your compiler to see if it supports this technology.

that is, Xcode's build setting Apple LLVM 7.0 to be selected as GUN99.

3) in the 1999 version of the ISO C standard, macros can be defined as functions with variable parameters. The syntax of a macro is similar to the syntax of a function. Here's an example:

//’…’指可变参数,被表示成零个或多个符号,包括里面的逗号.//当被调用时,在宏体(macro body)中,那些符号序列集合将代替里面的__VA_ARGS__标识符。#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)

4) GCC always supports complex macros, and it uses a different syntax so that you can give a variable parameter a name, just like any other parameter. For example, the following example:

#define debug(format, args...) fprintf (stderr, format, args)

5) CPP uses a special ' # # ' operation. The writing format is:

//这里,如果可变参数被忽略或为空,’##’操作将使预处理器(preprocessor)去除掉它前面的那个逗号。//如果你在宏调用时,确实提供了一些可变参数,GNU CPP也会工作正常,它会把这些可变参数放到逗号的后面。像其它的pasted macro参数一样,注意这些参数不是宏的扩展。#define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
    • C + + variable parameters, "# # __VA_ARGS__" Macro introduction and use»reille blog-read the code today, in a macro definition statement, found a previously not seen before the compiler scheduled macros: "__va_args__". At the time, it was inferred from the code statement that it represented a macro parameter: "..." (this is called an ellipsis), vaguely remembering that the ellipsis was used in the printf function declaration, presumably meaning a variable parameter, but not in-depth understanding.

Too many arguments provided to function-like macro invocation or

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.