I'm in the process of porting a lot of code originally written for the C51 compiler. The code makes extensive use of the "##" token-pasting feature. Explanation: http://www.keil.com/support/man/docs/c51/c51_pp_tokenpastingop.htm
How can I use token pasting (or a similar feature) with armcc 5.06? I'm using Keil MDK 5.28 for an STM32 target device.
Like the C51 compiler the C/C++ compiler in Arm Compiler 5 (armcc) comes with a C pre-processor. I just pre-processed a very simple example from the following Wikipedia page (see Token concatenation) with the -E option:
https://en.wikipedia.org/wiki/C_preprocessor(See Token concatenation.)
armcc -c -E -o test.txt test.c
… which results in the correct output for test.txt:
#line 1 "test.c"
typedef struct g_object_s g_object_t;
Further information can be found in the armcc 5.06 User Guide:
Arm's latest compiler, Arm Compiler 6 (armclang) also supports pre-processing:
Arm Compiler 6 and Arm Compiler 5 are both available in Keil MDK.
If you have any further questions or you're unable to get pre-processing to work, could you post a simple example to demonstrate what you're seeing. If you can also let us know about the specific task you're working on, that would be interesting too.
Thank you so much, Ed! This feature works just fine - it just doesn't seem to have any accompanying documentation about token pasting like most of the compiler documentation I've looked at (C51, C166, GCC, etc).
On a side note, not all compilers handle token pasting the same way (for ambiguous cases): https://complete-concrete-concise.com/programming/c/preprocessor-the-token-pasting-operator/
As far as I can tell (at least with --no_strict option), the armcc 5 compiler handles the example ambiguous case like Visual C++ (re-processing) rather than GCC (rejecting with error).
The specific task is hard to describe, but it relies heavily on token pasting to automatically generate functions (and their prototypes) to convert simple, high level commands into complex, low level code. This is done in the OS and makes life much easier for application programmers.
View all questions in Arm Compilers forum