![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
heatblazer
I`ve finalized the code, it`s not pretty and I think it can be improved for readability, but further will be a reflection emulation, I guess I don`t need overusing the macro any further:
You are not gaining anything using the preprocessor in such a manner. Here's what the first code pretty much amounts to after preprocessing:
Code:
#include <stdio.h>
typedef struct { int a; char b; float d; } S ;
int main(void) {
typedef struct { int type; } Node_int;;
typedef struct { S type; } Node_S;;
Node_int n;
n.type = 10000;
printf("%d \n", n.type);
Node_S s;
s.type.a=10;
s.type.b='c';
s.type.d = 22.2f;
printf("%d %c %f \n", s.type.a, s.type.b, s.type.d);
return 0;
}
You have a struct that contains an int, and another struct that contains a struct that contains an int, char, and float.
Your second code after preprocessing:
Code:
#include <stdio.h>
typedef struct { int a; char b; float d; } S ;
int main(void) {
typedef struct { int a; int b; int c; } S;;
S str;
str.a = 100;
str.b = 222;
str.c = 3333;
printf("%d %d %d sum is %d \n", str.a, str.b, str.c, str.a+str.b+str.c);
return 0;
}
You are creating a local struct of type "S" (containing three ints) that shadows a global struct of type "S" (with different members).
Neither of these is doing what you apparently want (based on your first post). You certainly aren't saving any space. Hint: You can't use the preprocessor to effect the program during execution (which was your originally stated goal).
At this point, just using discrete variables of the necessary types would be a major improvement.
Code:
#include <stdio.h>
int main(void)
{
int a;
char b;
float d;
a = 10;
b = 'c';
d = 22.2f;
printf("%d %c %f \n", a, b, d);
return 0;
}
You haven't given us the "what" and "why" I previously asked for, and your examples only serve to confuse, so there's not much more advice I can give at this point.