D
D
drVatman2015-01-08 22:35:51
Programming
drVatman, 2015-01-08 22:35:51

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

4 answer(s)
D
drVatman, 2015-01-09
@drVatman

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.

A
Alexander Taratin, 2015-01-08
@Taraflex

#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

G
GavriKos, 2015-01-08
@GavriKos

Well, the easiest option for runtime is to find out the size of the type, which differs in 64 and 32 systems.

M
mayorovp, 2015-01-09
@mayorovp

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 question

Ask a Question

731 491 924 answers to any question