Skip to content
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

Visual Studio 2017 and inttypes.h #29

Closed
kdekker opened this issue Jan 8, 2019 · 2 comments
Closed

Visual Studio 2017 and inttypes.h #29

kdekker opened this issue Jan 8, 2019 · 2 comments

Comments

@kdekker
Copy link

kdekker commented Jan 8, 2019

When I use latest win_flex.exe, the code produced, even in --wincompat mode contains lines like:

/* flex integer type definitions */

#ifndef FLEXINT_H
#define FLEXINT_H

/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */

#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L

/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
 * if you want the limit (max/min) macros for int types. 
 */
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS 1
#endif

#include <inttypes.h>
typedef int8_t flex_int8_t;
typedef uint8_t flex_uint8_t;
typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
typedef int flex_int32_t;
typedef unsigned char flex_uint8_t; 
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;

/* Limits of integral types. */
#ifndef INT8_MIN
#define INT8_MIN       

Unfortunately, Visual Studio does not set STDC_VERSION but has inttypes.h. Because the #else part of the code is used, duplicate macros for e.g. INT8_MIN will exist (and raise an compiler warning or even error if C4005 is marked as error, as was done in our case). Example:

1> c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\stdint.h(48): error C4005: 'INT8_MIN': macro redefinition
1> t:\obj.dbg.winx64\lib\sql\libsql_c\sqllex.cpp(57): note: see previous definition of 'INT8_MIN'
1> c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\stdint.h(49): error C4005: 'INT16_MIN': macro redefinition
1> t:\obj.dbg.winx64\lib\sql\libsql_c\sqllex.cpp(60): note: see previous definition of 'INT16_MIN'

Can you please enhance this macro and add a check on _MSCVER? The inttypes.h file is (at least) in any Windows 10 SDK. The other approach is to include stdint.h, which is - at least - existent for Visual Studio 2017 and later.

Any other suggestions are welcome.

@lexxmark
Copy link
Owner

I use the following lines to avoid warnings:
%top{
#include <stdint.h>
}

It seems it's already fixed in the original repo issue#307.
Should be available in the next flex release 2.6.5

Let's wait for the next release.

@kdekker
Copy link
Author

kdekker commented Jan 10, 2019

Many thanks. I now did a similar solution by not including any system header file. One of our own header files was included and that one included some system headers. The real cause is that Visual Studio does not adhere to C99 (or later) but still has its own stdint,h and/or inttypes.h.

I was not aware of mentioned issue, but that indeed addresses the same. Sorry for creating this duplicate.

However, the issue was created in mid 2018, but 2.6.5 seems not (yet) released. I took latest version, which was 2.6.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants