2

Hi I need some help in understand some C code:

#if 0
   some C code 1
#elif 0
   static int8 arry[10];
#pragma Align_to(32, arry)
   ASSERT(((int8ptr_t)arry) & 15) == 0)
#else
   ASSERT(((int8ptr_t)arry) & 15) == 0)
#endif

My questions:

  1. Is only the #else part compiled?

  2. What is the meaning of #pragma Align_to(32, arry) in the #elif 0 case?

4
  • 2
    I believe it's #pragma. gcc.gnu.org/onlinedocs/cpp/Pragmas.html Commented Jun 4, 2013 at 13:15
  • 1
    It's pragma instead of pramga. Commented Jun 4, 2013 at 13:16
  • Whether it's pragma or pramga isn't relevant... the #elif 0 means it is ignored. Only the #else is compiled as the OP surmises. Commented Jun 4, 2013 at 13:18
  • @KScottPiel Is that required? I've known compilers that process all #pragmas irrespective of whether or not they're in a #if Commented Jun 4, 2013 at 13:44

3 Answers 3

2

Actually better way to answer is ask compiler - use g++ -E or MSVC: cl /EP to print what is really compiled

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

3 Comments

Programming by experimentation? I'm not convinced that asking a compiler will give any definitive answer--unlike reading the C language spec/Standard will.
@Jens my answer related to first part of question - instead of solving puzzle "what part of preprocessor monster is compiled" I'd prefer to generate expanded file
+1 Fair enough, but we need to be aware of the experimentation pitfalls in general.
0

Yes, the #else part is what is compiled.


The #pragma directive is a compiler specific directive. As you compiler was not specified, it could mean anything.

In your case #pragma Align_to(32, arry), likely tells the compiler to insure variable 'arry' is place in memory on a 32 byte boundary. This is typically for performance reasons or compatibility concerns. You may also want to look into the keyword __attribute__ use to control similar variable attributes.

Comments

0

Answer to 1: Yes, but note that even the parts within #if 0 etc. must consist of valid preprocessing tokens. This means that this will fail with a diagnostic:

#if 0
That's what C is all about
#endif

because there's an unterminated character constant introduced by the lone '. Same goes for unterminated string literals.

Answer to 2: The pragma is a hint to the compiler that the address of arry shall be aligned on a multiple of 32.

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.