ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
679 stars 273 forks source link

Compound literal arguments don't work #92

Open kaimac1 opened 8 years ago

kaimac1 commented 8 years ago

When passing a compound literal to a function that takes a struct argument, CMock gets confused about the number of arguments that were passed.

modem_at_ExpectAndReturn((ATCmd){"AT+CIPSTART=\"udp\",\"domain\",\"1234\"\r", "CONNECT OK"}, 0);

tests/test_udp.c:10:105: error: macro "modem_at_ExpectAndReturn" passed 3 arguments, but takes just 2
modem_at_ExpectAndReturn((ATCmd){"AT+CIPSTART=\"udp\",\"domain\",\"1234\"\r", "CONNECT OK"}, 0);

It seems to somehow be interpreting each member of the compound literal as a separate argument. Adding the next member of the struct gives '... passed 4 arguments, but takes just 2'.

mvandervoord commented 8 years ago

Interesting.

First, I must admit I've never thought to pass a compound literal as an argument like this in C. That being said, I'm not sure why it wouldn't work as normal. I suspect it has something to do with the way compound literals are handled inside macros. I suspect that since macros are processed before the compound literal, it's taking it apart ahead of time?

For now, you can assign these to a variable ahead of time... I'll have to see if there is anything we can do about this long-term (based on where the problem is).

:)