views:

115

answers:

2

I am porting some C++ code to GCC, and apperantly it isn't happy with C++ style casting when sapces are involved, as in unsigned int(-1), long long(ShortVar) etc... It gives an error: expected primary-expression before 'long'.

Is there any way to make peace with GCC without going over each one of those and rewrite in c-style?

+4  A: 
GMan
I believe they're function-style casts. They're not valid in C.
rlbond
@rlbond: I think you're right, I thought they said (unsigned int)(-1), which also shouldn't work.
GMan
@GMan: Thanks. The point was that there are no parenthesis around the type names, as opposed to C. I'm trying to save the trouble of going over all of them, not specifically avoiding/favoring any sort of cast. Thought there might be some switch/hack.
uj2
@GMan, I found out why they weren't parsed by GCC :)
Kornel Kisielewicz
GMan, it is the first time I see the C++0x notation you provided. Can you please offer any link/documentation on this (I'm curious to read more on it).Thanks.
utnapistim
@GMan, i'm glad you are an identity activist too, now xD
Johannes Schaub - litb
@utnapistim: They are called `template aliases`, you can get some results in Google with that. It's in §14.5.7 in the C++0x draft (n3092.pdf). @Johannes: Haha, I couldn't help it any longer.
GMan
+2  A: 

GCC is correctly crying -- unsigned int(-1) is a notation that is not conformant with the C++03 standard (5.4.2):

An explicit type conversion can be expressed using functional notation (5.2.3), a type conversion operator (dynamic_cast, static_cast, reinterpret_cast, const_cast), or the cast notation:

cast-expression:
   unary-expression
   ( type-id ) cast-expression

Ergo, you can either correct the cast with the parenthesis, follow the excellent suggestions proposed by GMan :) -- and I'd truly recommend the latter.

Edit: the functional notation requires a simple-type-specifier:

5.2.3 - A simple-type-specifier (7.1.5) followed by a parenthesized expression-list constructs a value of the specified type given the expression list.

Simple type specifiers do not include the composite ones (the ones with spaces).

Kornel Kisielewicz