New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`near` and `far` are reserved keywords in Visual C #1959

Open
BertrandBordage opened this Issue Oct 29, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@BertrandBordage
Contributor

BertrandBordage commented Oct 29, 2017

When defining an extension type containing two float attributes near & far, I get this error when building on Windows using Visual C:

Error C2208 : 'float' no members defined using this type

This was a bit tricky to find the cause, but turns out far and near are reserved keywords in Visual C.

Of course, a workaround is to rename the attributes in Cython, for example to _near & _far, but we end up with uglier code for a compiler implementation detail that shouldn’t interfere with the way we write Cython code.

So ideally, these reserved keywords should be translated to available names when generating the C source.

@scoder

This comment has been minimized.

Show comment
Hide comment
@scoder

scoder Oct 29, 2017

Contributor

It should be enough to add both as non-C-safe identifiers here:

iso_c99_keywords = set(
['auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do',
'double', 'else', 'enum', 'extern', 'float', 'for', 'goto', 'if',
'int', 'long', 'register', 'return', 'short', 'signed', 'sizeof',
'static', 'struct', 'switch', 'typedef', 'union', 'unsigned', 'void',
'volatile', 'while',
'_Bool', '_Complex'', _Imaginary', 'inline', 'restrict'])

That will have an impact on existing code, though, which is annoying for something as non-standard as this... @robertwb, do you think we should add those? Do we need a transition phase here?

@BertrandBordage, note that you can use cnames to rename fields at the C level.

Contributor

scoder commented Oct 29, 2017

It should be enough to add both as non-C-safe identifiers here:

iso_c99_keywords = set(
['auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do',
'double', 'else', 'enum', 'extern', 'float', 'for', 'goto', 'if',
'int', 'long', 'register', 'return', 'short', 'signed', 'sizeof',
'static', 'struct', 'switch', 'typedef', 'union', 'unsigned', 'void',
'volatile', 'while',
'_Bool', '_Complex'', _Imaginary', 'inline', 'restrict'])

That will have an impact on existing code, though, which is annoying for something as non-standard as this... @robertwb, do you think we should add those? Do we need a transition phase here?

@BertrandBordage, note that you can use cnames to rename fields at the C level.

@BertrandBordage

This comment has been minimized.

Show comment
Hide comment
@BertrandBordage

BertrandBordage Oct 29, 2017

Contributor

Thank you @scoder! Yes, I’ll use the explicit C name notation in the meantime.

Contributor

BertrandBordage commented Oct 29, 2017

Thank you @scoder! Yes, I’ll use the explicit C name notation in the meantime.

@AraHaan

This comment has been minimized.

Show comment
Hide comment
@AraHaan

AraHaan Nov 2, 2017

Contributor

Well, technically Visual C/C++ (MSVC) does not have full c99 because it does not have things like VLAs which was required for c99 but became optional in c11. So MSVC is c98, c90, and c11 complient but not c99. (Sadly for c99 on MSVC it requires use of clang-cl...

And I hate clang for some reason... If I wanted clang I would be using linux to cross compile to Windows.

Contributor

AraHaan commented Nov 2, 2017

Well, technically Visual C/C++ (MSVC) does not have full c99 because it does not have things like VLAs which was required for c99 but became optional in c11. So MSVC is c98, c90, and c11 complient but not c99. (Sadly for c99 on MSVC it requires use of clang-cl...

And I hate clang for some reason... If I wanted clang I would be using linux to cross compile to Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment