A problem occurred to me. Somebody might show me how to remove the @
.
I am writing C for a UC and I am lazy; so I want to solve easy problems with macros, e.g. switching on an LED.
I managed to do something like that:
#include <stdio.h>
#define BIT_STD_SET(PORT, BITNUM) ((PORT) |= (1<<(BITNUM)))
#define BIT_STD_CLE(PORT, BITNUM) ((PORT) &= ~(1<<(BITNUM)))
#define BIT_STD_TOG(PORT, BITNUM) ((PORT) ^= (1<<(BITNUM)))
#define LEDPORT_0 C
#define LEDPAD_0 3 /*Blau*/
#define LEDPORT_1 D
#define LEDPAD_1 4 /*GelbWeis*/
#define PO(n) LEDPORT_##n
#define POR(n) PORT@PO(n)
#define PA(n) LEDPAD_##n
#define PAD(n) PA(n)
#define LEDAN(n) BIT_STD_SET(POR(n),PAD(n))
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)
int main()
{
printf("%s\n",h(LEDAN(0)));
printf("%s\n",h(LEDAN(1)));
printf("\n");
printf("%s\n",h(LEDAN(1)));
printf("\n");
printf("%s\n",h(POR(0)));
printf("%s\n",h(POR(1)));
printf("%s\n",h(f(0,1)));
printf("%s\n",g(f(0,1)));
return 0;
}
p@d:~/$ gcc ./mak.c
And got:
p@d:~/$ ./a.out
Answer:
((PORT@C) |= (1<<(3)))
((PORT@D) |= (1<<(4)))
((PORT@D) |= (1<<(4)))
PORT@C
PORT@D
01
f(0,1)
The @
should be removed. Unfortunately, I do not know how. I have read some manuals, but I do not know how to express myself.