Error: "expected specifier-qualifier-list before ‘typeof’"

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is OFF
Smilies are ON
Topic review
   

Expand view Topic review: Error: "expected specifier-qualifier-list before ‘typeof’"

Re: Error: "expected specifier-qualifier-list before ‘typeof’"

Post by drekka » 08 Dec 2009, 09:04

Hi

I just encountered this too.

I tried your fix and it worked. But before that I also re-wrote the #define like this:

#define DHC_MOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(__typeof__(variable))]

Notice two changes. Firstly the __typeof__ and secondly the &variable. I needed both changes to get this to work with the -std=c99 flag. It also works with the -std=gnu99 flag as well.

The other thing that needs to be added to the doco is that you must pass in a variable. Ie. you cannot just go OCMOCK_VALUE(1). Although I'd like it if the macro could be expanded to be able to handle it as well.

FYI: I'm new to Objective C so whilst I got this working, it may not be the best solution :)

ciao
Derek

Error: "expected specifier-qualifier-list before ‘typeof’"

Post by Dan K » 20 Oct 2009, 11:04

While developing a project with OCMock (using XCode-3.2 with GCC-4.2 on Mac OS X 10.6.1 "Snow Leopard" and targeting the IPhone Simulator for IPhone OS 3.1), I ran into a problem using OCMOCK_VALUE. Since it seemed a bit obscure, maybe my experience will help someone else avoid some frustration.

At some point in my test suite, I needed to mock out a database result set and in particular to stub out the method which returns an int value for a column. I wrote the following:

Code: Select all
    id rs = [OCMockObject mockForClass:[FMResultSet class]];
    int intval = 4;
    [[[rs stub] andReturnValue: OCMOCK_VALUE(intval)] intForColumn:@"points"];


which returned the following compiler error: expected specifier-qualifier-list before ‘typeof'.

What was going on was that OCMOCK_VALUE was using the GCC 'typeof' extension, and that my unit test target was set up to use the -std=c99 flag for GCC which turns off the GNU extensions (such as 'typeof'). Note that I'd never actually set my target to use the c99 standard language flavor -- that's just what XCode chose for me when I set up the target.

The solution was simple: just set -std=gnu99 in the test target. Note that I only needed to set this on the testing target where I was using OCMock (and OCMOCK_VALUE in particular) -- the standard in use for my deployed target remained the same (c99 in this case).

Top

cron