求助啊macro "SIGNAL" passed 3 arguments.callee,but takes just 1

c++ - Too many actual parameters for macro? - Stack Overflow
to customize your list.
Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
J it only takes a minute:
#include &iostream&
#define ADD(x,y)
int main( int argc, char** argv )
cout && ADD(1,2,) &&
Compiler output:
1>Compiling...
1>main.cpp
1>c:\warn_test\main.cpp(9) : warning C4002: too many actual parameters for macro 'ADD'
Why isn't this an error?
g++ (GCC) 4.2.1
[FreeBSD] gives more reasonable (in my mind) output:
main.cpp:9:18: error: macro "ADD" passed 3 arguments, but takes just 2
main.cpp: In function 'int main(int, char**)':
main.cpp:9: error: 'ADD' was not declared in this scope
Though I'm not entirely sure what either compiler thinks the third argument is.
EDIT: Added complete gcc output and version info.
3,361132979
36.2k84079
You use ADD(1,2,), note the second ,. Remove that and it will compile just fine!
@schnaader: You are right, I read too fast. Sorry.
Please provide more details about the compiler in question. I use: g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5, and this is the result I get:
test.cpp:9: error: macro "ADD" passed 3 arguments, but takes just 2
test.cpp: In function ‘int main(int, char**)’:
test.cpp:9: error: ‘ADD’ was not declared in this scope
Sorry, again a bit too fast :-). I see you tagged it with visual studio. VS is more tolerant than g++. I suppose that -- because it is easy to resolve in this case -- it automatically corrects it.
I'm going to throw out a complete guess, inspired by Steve Jessop's comment that it's related to variadic macro support.
Possibly it was easier to make it a warning when the visual studio team implemented variadic macros? I've noticed varying levels of tolerance when implementing code like:
#define MACRO(...) my_func(true, __VA_ARGS__);
MACRO(1,,2); // Missing argument
MACRO(1,); // missing tail
MACRO(); // no arguments
Some compilers error, warn or ignore the various situations. I don't know what the standards says tho.
2,23311325
I guess this is somewhat compiler's choice. If there was a third parameter, it would perhaps be more problematic, but as there isn't, you can argue about just ignoring the comma or throwing an error. Microsoft seems to be more error tolerant often (like in IE HTML parsing).
35.2k572107
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .24681
Stack Overflow works best with JavaScript enabledc++ - macro MOCK_METHOD passed 3 arguments, but takes just 2 error with std::pair - Stack Overflow
to customize your list.
Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
J it only takes a minute:
I'm using Google Mock 1.6.0. When using the MOCK_METHODN macros, it seems to think I'm passing 3 arguments for methods that return a std::pair:
#include &gmock/gmock.h&
#include &utility&
class IFoo {
virtual std::pair&int, int& bar() = 0;
class MockFoo {
MOCK_METHOD0(bar, std::pair&int, int&());
int main() {
Compiler output (GCC 4.6.3):
main.cpp:9:44: error: macro "MOCK_METHOD0" passed 3 arguments, but takes just 2
main.cpp:9:5: error: ‘MOCK_METHOD0’ does not name a type
This error doesn't appear if I:
Replace std::pair&int, int& with a simple type like int or void
Use on a method that has a std::pair argument, instead of returning it
4,83532552
This appears to be a bug with version 1.6.0. The same code works with version 1.7.0, so the best solution would be to upgrade to that.
Alternately, compiling with Clang also runs into the same error, but provides a strong clue where the error is:
main.cpp:9:38: error: too many arguments provided to function-like macro invocation
MOCK_METHOD0(bar, std::pair&int, int&());
main.cpp:9:5: error: C++ requires a type specifier for all declarations
MOCK_METHOD0(bar, std::pair&int, int&());
^~~~~~~~~~~~
2 errors generated.
Looks like a buggy macro expansion is interpreting the , inside std::pair&int, int& as another argument. Therefore, you can also work around the issue by avoiding the ,, for instance using a typedef:
typedef std::pair&int, int& MyT
class MockFoo {
MOCK_METHOD0(bar, MyType());
4,83532552
You still need a typedef if the return type contains an unprotected comma, but that's much rarer.
Use typedef
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .24681
Stack Overflow works best with JavaScript enabledMacro Arguments - The C Preprocessor
Previous:&,
3.3 Macro Arguments
Function-like macros can take arguments, just like true functions.
To define a macro that uses arguments, you insert parameters
between the pair of parentheses in the macro definition that make the
macro function-like.
The parameters must be valid C identifiers,
separated by commas and optionally whitespace.
To invoke a macro that takes arguments, you write the name of the macro
followed by a list of actual arguments in parentheses, separated
by commas.
The invocation of the macro need not be restricted to a
single logical line&it can cross as many lines in the source file as
The number of arguments you give must match the number of
parameters in the macro definition.
When the macro is expanded, each
use of a parameter in its body is replaced by the tokens of the
corresponding argument.
(You need not use all of the parameters in the
macro body.)
As an example, here is a macro that computes the minimum of two numeric
values, as it is defined in many C programs, and some uses.
#define min(X, Y)
((X) & (Y) ? (X) : (Y))
x = min(a, b);
x = ((a) & (b) ? (a) : (b));
y = min(1, 2);
y = ((1) & (2) ? (1) : (2));
z = min(a + 28, *p);
z = ((a + 28) & (*p) ? (a + 28) : (*p));
(In this small example you can already see several of the dangers of
macro arguments.
See , for detailed explanations.)
Leading and trailing whitespace in each argument is dropped, and all
whitespace between the tokens of an argument is reduced to a single
Parentheses within each a a comma within
such parentheses does not end the argument.
However, there is no
requirement for square brackets or braces to balance, and they do not
prevent a comma from separating arguments.
macro (array[x = y, x + 1])
passes two arguments to macro: array[x = y and x +
If you want to supply array[x = y, x + 1] as an argument,
you can write it as array[(x = y, x + 1)], which is equivalent C
All arguments to a macro are completely macro-expanded before they are
substituted into the macro body.
After substitution, the complete text
is scanned again for macros to expand, including the arguments.
may seem strange, but it is carefully designed so you need not worry
about whether any function call is actually a macro invocation.
run into trouble if you try to be too clever, though.
See , for detailed discussion.
For example, min (min (a, b), c) is first expanded to
min (((a) & (b) ? (a) : (b)), (c))
and then to
((((a) & (b) ? (a) : (b))) & (c)
? (((a) & (b) ? (a) : (b)))
(Line breaks shown here for clarity would not actually be generated.)
You can leave m this is not an error to the
preprocessor (but many macros will then expand to invalid code).
You cannot leave ou if a macro takes two arguments,
there must be exactly one comma at the top level of its argument list.
Here are some silly examples using min:
) & (b) ? (
) & ( ) ? (a
) & ( ) ? (
==& (((,)) & ( ) ? ((,)) : ( ))
error--& macro "min" requires 2 arguments, but only 1 given
error--& macro "min" passed 3 arguments, but takes just 2
Whitespace is not a preprocessing token, so if a macro foo takes
one argument, foo&() and foo&(&) both supply it an
empty argument.
Previous GNU preprocessor implementations and
documentation were incorrect on this point, insisting that a
function-like macro that takes a single argument be passed a space if an
empty argument was required.
Macro parameters appearing inside string literals are not replaced by
their corresponding actual arguments.
#define foo(x) x, "x"
==& bar, "x"compiler errors - MariaDB C++ Connector compile - Stack Overflow
to customize your list.
Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
J it only takes a minute:
I'm trying to compile a simple c++ file that is suppose to use the mariadbc++ connector. For some reason I ran into alot of trouble with that. I get strange error messages. I neither understand them, nor do I know how to fix them.
I did a lot of research, but either nobody else ran into these problems or I just cant find them.
I installed following packages:
mariadb-client
mariadb-client-5.5
mariadb-server
libmariadbclient18
libmysqlclient18
libmysqlcppconn7
libmysqlcppconn-dev
libmariadbclient-dev
libmariadb-dev
I'm on a x64 Ubuntu 14.04 System (well Pinguy OS, but I guess, that doesn't matter)
I tried to build following programm:
#include &my_global.h&
#include &mysql.h&
#include "mysql_driver.h"
int main(int argc, char **argv)
sql::mysql::MySQL_Driver *
sql::Connection *
sql::Statement *
driver = sql::mysql::MySQL_Driver::get_mysql_driver_instance();
con = driver-&connect("tcp://localhost:3306","root", "herein");
if (!con-&isValid()) exit(1);
stmt = con-&createStatement();
stmt-&execute("use testtb");
stmt-&execute("INSERT INTO Testtable(id, label) VALUES (1, 1)");
And I tried this command:
g++ -lmysqlcppconn -g src/test_mariadb.cpp -o bin/test_mariadb $(mysql_config --cflags) $(mysql_config --libs)
where under in src/ my source files are and in bin/ my binaries.
And finally the Compile Errors I get:
In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from /usr/include/boost/assert.hpp:82,
from /usr/include/boost/smart_ptr/scoped_ptr.hpp:15,
from /usr/include/boost/scoped_ptr.hpp:14,
from /usr/include/mysql_driver.h:30,
from src/test_mariadb.cpp:3:
/usr/include/c++/4.8/bits/stl_algobase.h:239:56: error: macro "min" passed 3 arguments, but takes just 2
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
/usr/include/c++/4.8/bits/stl_algobase.h:260:56: error: macro "max" passed 3 arguments, but takes just 2
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
In file included from /usr/include/boost/mpl/aux_/begin_end_impl.hpp:21:0,
from /usr/include/boost/mpl/begin_end.hpp:18,
from /usr/include/boost/mpl/iter_fold.hpp:18,
from /usr/include/boost/variant/detail/initializer.hpp:28,
from /usr/include/boost/variant/variant.hpp:31,
from /usr/include/boost/variant.hpp:17,
from /usr/include/cppconn/connection.h:31,
from /usr/include/cppconn/driver.h:30,
from /usr/include/mysql_driver.h:32,
from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_begin.hpp:20:57: error: macro "test" passed 2 arguments, but takes just 1
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_begin, begin, true)
In file included from /usr/include/boost/mpl/sequence_tag.hpp:18:0,
from /usr/include/boost/mpl/begin_end.hpp:19,
from /usr/include/boost/mpl/iter_fold.hpp:18,
from /usr/include/boost/variant/detail/initializer.hpp:28,
from /usr/include/boost/variant/variant.hpp:31,
from /usr/include/boost/variant.hpp:17,
from /usr/include/cppconn/connection.h:31,
from /usr/include/cppconn/driver.h:30,
from /usr/include/mysql_driver.h:32,
from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_tag.hpp:20:54: error: macro "test" passed 2 arguments, but takes just 1
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_tag, tag, false)
In file included from /usr/include/boost/mpl/aux_/O1_size_impl.hpp:20:0,
from /usr/include/boost/mpl/O1_size.hpp:19,
from /usr/include/boost/mpl/iter_fold.hpp:19,
from /usr/include/boost/variant/detail/initializer.hpp:28,
from /usr/include/boost/variant/variant.hpp:31,
from /usr/include/boost/variant.hpp:17,
from /usr/include/cppconn/connection.h:31,
from /usr/include/cppconn/driver.h:30,
from /usr/include/mysql_driver.h:32,
from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_size.hpp:20:1: error: macro "test" passed 2 arguments, but takes just 1
BOOST_MPL_HAS_XXX_TRAIT_DEF(size)
In file included from /usr/include/boost/mpl/apply_wrap.hpp:23:0,
from /usr/include/boost/mpl/bind.hpp:27,
from /usr/include/boost/mpl/lambda.hpp:18,
from /usr/include/boost/mpl/iter_fold.hpp:20,
from /usr/include/boost/variant/detail/initializer.hpp:28,
from /usr/include/boost/variant/variant.hpp:31,
from /usr/include/boost/variant.hpp:17,
from /usr/include/cppconn/connection.h:31,
from /usr/include/cppconn/driver.h:30,
from /usr/include/mysql_driver.h:32,
from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_apply.hpp:22:58: error: macro "test" passed 2 arguments, but takes just 1
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_apply, apply, false)
In file included from /usr/include/boost/mpl/quote.hpp:23:0,
from /usr/include/boost/mpl/aux_/full_lambda.hpp:25,
from /usr/include/boost/mpl/lambda.hpp:22,
from /usr/include/boost/mpl/iter_fold.hpp:20,
from /usr/include/boost/variant/detail/initializer.hpp:28,
from /usr/include/boost/variant/variant.hpp:31,
from /usr/include/boost/variant.hpp:17,
from /usr/include/cppconn/connection.h:31,
from /usr/include/cppconn/driver.h:30,
from /usr/include/mysql_driver.h:32,
from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_type.hpp:20:55: error: macro "test" passed 2 arguments, but takes just 1
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_type, type, true)
In file included from src/test_mariadb.cpp:1:0:
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected unqualified-id before ‘const’
min(const _Tp& __a, const _Tp& __b)
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected initializer before ‘const’
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected unqualified-id before ‘const’
max(const _Tp& __a, const _Tp& __b)
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected initializer before ‘const’
In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
from /usr/include/c++/4.8/ios:40,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from /usr/include/boost/assert.hpp:82,
from /usr/include/boost/smart_ptr/scoped_ptr.hpp:15,
from /usr/include/boost/scoped_ptr.hpp:14,
from /usr/include/mysql_driver.h:30,
from src/test_mariadb.cpp:3:
/usr/include/c++/4.8/bits/stl_algobase.h:239:5: error: ‘std::min’ declared as an ‘inline’ variable
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
/usr/include/c++/4.8/bits/stl_algobase.h:239:5: error: template declaration of ‘const _Tp& std::min’
/usr/include/c++/4.8/bits/stl_algobase.h:242:7: error: expected primary-expression before ‘if’
if (__comp(__b, __a))
/usr/include/c++/4.8/bits/stl_algobase.h:242:7: error: expected ‘}’ before ‘if’
/usr/include/c++/4.8/bits/stl_algobase.h:244:7: error: expected unqualified-id before ‘return’
return __a;
/usr/include/c++/4.8/bits/stl_algobase.h:260:5: error: ‘max’ declared as an ‘inline’ variable
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
/usr/include/c++/4.8/bits/stl_algobase.h:260:5: error: template declaration of ‘const _Tp& max’
/usr/include/c++/4.8/bits/stl_algobase.h:263:7: error: expected primary-expression before ‘if’
if (__comp(__a, __b))
/usr/include/c++/4.8/bits/stl_algobase.h:263:7: error: expected ‘}’ before ‘if’
/usr/include/c++/4.8/bits/stl_algobase.h:265:7: error: expected unqualified-id before ‘return’
return __a;
/usr/include/c++/4.8/bits/stl_algobase.h:266:5: error: expected declaration before ‘}’ token
A header you have included has defined preprocessor macros named min, max and test. These have then conflicted with identifiers used (e.g. for method names) in other header files you have included.
Assuming that those macros have been defined in one of these headers:
#include &my_global.h&
#include &mysql.h&
you could add #undefs before you include mysql_driver.h, e.g.:
#include &my_global.h&
#include &mysql.h&
#undef min
#undef max
#undef test
#include "mysql_driver.h"
You could also consider re-arranging the order in which you include the files, or look into what headers are defining these and see whether the definition of these macros can be disabled.
2,63131127
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .24681
Stack Overflow works best with JavaScript enabledsyslog.h和android的log系统冲突问题
工作中发现一个问题,c文件不能打log,说明白点,就是不能调用ALOGE ALOGD
ALOGV这些函数,会报错,类似下面的错误
& error: macro "LOG_PRI" passed 3 arguments, but
takes just 1
& error: 'LOG_PRI' undeclared (first use in this
2.解决办法
研究发现,是因为包含了头文件”syslog.h“引起的冲突,去掉就ok了。
3.原因解析
ALOE函数的实现在”system/core/include/log/log.h“文件中,实现过程如下
#ifndef ALOGE
#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG,
__VA_ARGS__))
#ifndef ALOG
#define ALOG(priority, tag, ...) \
LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
会调用到LOG_PRI,文件下半部分有LOG_PRI实现如下
#ifndef LOG_PRI
#define LOG_PRI(priority, tag, ...) \
android_printLog(priority, tag, __VA_ARGS__)
这是正常的调用流程。
然而包含了"syslog.h"后,这个系统文件里也有对LOG_PRI的实现如下
LOG_PRI(x)&&&
((x) & LOG_PRIMASK)
因为系统文件syslog.h里的实现在前,优先级高,所以优先使用了,就造成了冲突。
想使用android的LOG系统,千万不要包含”syslog.h“文件,切记!
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 takes no arguments 的文章

 

随机推荐