Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__int64 for GCC as a Preprocessor Option

Usually Microsoft code uses __int64 which is not understood by GCC. I know I can write it as a macro like this:

#define __int64 long long

But I don't want to do this, due to code portability. I'm trying to give GCC the following Preprocessor Option:

-D__int64="long long"

I get the following error due to the space between the two long's:

gcc.exe: error: long: No such file or directory

How to fix it ?

like image 777
Hesham Eraqi Avatar asked Jan 27 '15 15:01

Hesham Eraqi


People also ask

What is__ int64 in C?

The __int64 type is synonymous with type long long .

Is GCC a preprocessor?

You can invoke the preprocessor either with the cpp command, or via gcc -E . In GCC, the preprocessor is actually integrated with the compiler rather than a separate program, and both of these commands invoke GCC and tell it to stop after the preprocessing phase.

What is __ int32?

As other have said signed __int32 is a 32-bit 2's complement integer and unsigned __int32 is a 32-bit unsigned integer. Using __ before int32 to form __int32 makes it a reserved identifier.

What does GCC output?

The output is in the form of an assembler code file for each non-assembler input file specified. By default, the assembler file name for a source file is made by replacing the suffix ' .


2 Answers

You could use int64_t, the standard name for that type, but it will only work if the code does #include <stdint.h>, and that's perhaps hoping for too much.

Otherwise you could try to "sneak" in a typedef in some common header:

typedef long long __int64;

Perhaps doing that only if GCC is detected.

Fixing it "your way" should certainly be possible, it looks like some quoting issue.

like image 75
unwind Avatar answered Sep 16 '22 20:09

unwind


Sounds like you have a double-eval issue if your example doesn't work. If you can't figure out why that is happening you can try using gcc's -include or -imacros option. You would create a new file gcc_extra_definess with the #defines you want to add, and call gcc -include gcc_extra_defines ... to get gcc to read that file and include it before reading the source file. This is a bit easier than a bunch of -D options for defining multiple things, particularly if you have quoting issues or want things other than macros.

like image 29
Chris Dodd Avatar answered Sep 19 '22 20:09

Chris Dodd