GCC不喜欢带有空格的C ++风格的转换 [英] GCC doesn't like C++ style casts with spaces

查看:526
本文介绍了GCC不喜欢带有空格的C ++风格的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一些C ++代码移植到GCC,并且如果在code> unsigned int(-1)时,它不喜欢C ++风格的转换, long long(ShortVar) etc ...给出一个错误:在'long'之前的预期主表达式 / p>

有没有什么办法让GCC和平,而不经过每一个,并重写c风格?

解决方案

GCC正在哭泣 - unsigned int(-1)是不符合C ++ 03标准(5.4.2):


显式类型转换可以使用函数表示法(5.2.3) dynamic_cast,static_cast,reinterpret_cast,const_cast)或者转换符号:




  
unary-expression
(type-id)cast-expression

你可以用圆括号修正演员,按照GMan提出的优秀建议:) - 我真的会推荐后者。



编辑: 功能符号需要一个简单类型说明符:


5.2.3 -


简单类型说明符不包括在表达式列表中的指定类型的值。复合的(具有空格的那些)。


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?

解决方案

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).

这篇关于GCC不喜欢带有空格的C ++风格的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆