|
-
July 24th, 2007, 05:57 PM
#1
Preprocessor metaprogramming?
Hi there,
I got stuck on this one today while reviewing some deeply embedded operating system code.
The developer was clearing the instruction pipeline in a deeply embedded microcontroller operating system and he used assembler nop's to do it. This is certainly legitimate, assuming that the underlying CPU architecture has no serializing instructions, which it did not. He was supporting several architectures, each one of which had different pipeline stages and it was ugly:
Code:
#ifdef(Architecture_Something)
_asm("nop")
_asm("nop")
#elif defined(Architecture_Something_Else)
_asm("nop")
_asm("nop")
_asm("nop")
_asm("nop")
#endif
So after this long lead-in...
Is it possible to create a macro 'nopN' which generates a sequence of N instances of a repeated 'nop' line? I know that C++ template metaprogramming would do it with no problem. But can the C-preprocessor do this?
Maybe I did it once and forgot how.
Sincerely, Chris.
You're gonna go blind staring into that box all day.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|