3

We develop code for embedded PowerPC architectures.

Our compiler supports something called asm Macros.

Here an excerpt from the handbook:

asm Macro Syntax

An asm macro definition looks much like a function definition, including a return type and parameter list, and function body.

The syntax is:

asm [volatile] [return-type] macro-name ( [ parameter-list ] )
 {
 % storage-mode-list (must start in column 1)
 ! register-list     (“!” must be first non-whitespace)
   asm-code      
 } (must start in column 1

Is this standard C? My compiler does not list this as an extension in his handbook.

Clarification after first answer:

I'm aware the part withen { } is not defined by standard C. I meant the function like construct after asm and before the closing ).

RedX
  • 14,749
  • 1
  • 53
  • 76

2 Answers2

4

No, it is not standard C. Anything architecture-specific, like assembly code, is going to be an implementation-specific extension just about by definition.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • 1
    Oh, sorry maybe i should have worded it more accurately. I'm aware that the part within `{ assembler or similar }` is not defined by standard C. I meant the whole function-like construct. – RedX Feb 18 '15 at 19:00
  • No, nothing about that is standard either. – Carl Norum Feb 18 '15 at 19:02
0

The asm keyword is not standard in C, it is reserved in C++, but in both cases the the syntax is implementation specific as described here:

asm-declaration gives the ability to embed assembly language source code within a C++ program. This declaration is conditionally-supported and implementation defined, meaning that it may not be present and, even when provided by the implementation, it does not have a fixed meaning.

It's use to define a macro is new to me and interesting however.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • The syntax is not implementation-defined in C++. The standard (C++03 7.4) specifies the actual syntax for inline asm to be `asm "NOP";` and nothing else. The implementation-defined part is only the actual assembly inside the quotation marks, in this case the NOP instruction. – Lundin Feb 19 '15 at 10:16
  • @Lundin : Good point, though that defined syntax does not cover the syntax in the question nor the input/output/clobber specification syntax in GCC, and historically there has been little standardisation - expect compilers to vary is my advice. VC++ uses a different syntax introduced by `__asm`, which is the more correct form for non-standard compiler extensions. – Clifford Feb 19 '15 at 18:52