Answer the question
In order to leave comments, you need to log in
How do you know what the code is compiling for?
There is a code in C (extension for php). I need to understand in it what assembly it is compiled for: 32 or 64 bits. It is desirable, of course, with a macro so that there are 2 branches: one is executed on 64x, the second on 32x bits. But if it is impossible with macros, then at least in runtime. Runs under linux (debian). Although the most general solution is desirable.
Answer the question
In order to leave comments, you need to log in
After digging in the zend api sources, the zend_long.h file was found, and in it the ZEND_ENABLE_ZVAL_LONG64 determinant, which is just responsible for the bit depth of integers in php. Therefore, the macro is: #ifdef ZEND_ENABLE_ZVAL_LONG64.
#if _WIN32 || _WIN64
#if _WIN64
#define ENV64BIT
#else
#define ENV32BIT
#endif
#endif
// Check GCC
#if __GNUC__
#if __x86_64__ || __ppc64__
#define ENV64BIT
#else
#define ENV32BIT
#endif
#endif
Well, the easiest option for runtime is to find out the size of the type, which differs in 64 and 32 systems.
If you are interested in the runtime version, then here is the simplest option: sizeof(void*) - can be equal to 4 or 8 :)
But, if it's not a secret, what exactly is the difference between these two branches? In all my projects, only the correct arrangement of the size_t and ptrdiff_t types was enough for me, and I never had to resort to an explicit definition of bitness.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question