7

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 ?

11
  • 3
    You need stdint.h included, as @unwind answered. Commented Jan 27, 2015 at 15:24
  • 2
    You also need to compile with C99 standard or later. gcc -std=c99 Commented Jan 27, 2015 at 15:25
  • 1
    May I ask why you need an 64 bit int, I'm just curious why the 32 bit wouldn't be enough? Commented Jan 27, 2015 at 16:02
  • 1
    @HeshamEraqi That is not a valid reason, you're performance will go down because of using a larger register than you need. I do use 8 or 16 bit ints if my variable isn't going to need all that space. @ LưuVĩnhPhúc I think our friend only wanted to know his situation, no need to belittle him. Commented Jan 27, 2015 at 16:42
  • 1
    -D__int64="long\ long" (add more `\` before the space until it works) Commented Jan 27, 2015 at 23:48

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Changing the code is not a preferred option in my situation. I tried different quoting combinations to "my way", and it didn't work.
3

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.

Comments

2

Looks like a quoting problem caused by gcc seeing only

gcc ... -D__int64=long long

Can you show us the script or Makefile snippet you use? What shell is it?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.