I was working with C++ for a long time and now I am on a C project.
I am in the process of converting a C++ program to C.
I am having difficulty with the constants used in the program.
In the C++ code we have constants defined like
static const int X = 5 + 3;
static const int Y = (X + 10) * 5
static const int Z = ((Y + 8) + 0xfff) & ~0xfff
In C, these definitions throw error. When I use #defines instead of the constants like
#define X (5+3);
#define Y (((X) + 10) * 5)
#define Z ((((Y) + 8) + 0xfff) & ~0xfff)
the C compiler complains about the definitions of "Y" and "Z".
Could anyone please help me to find a solution for this.
#definein c causes the preprocessor to do a textual substitution before compilation, so imagine taking the contents of X and plugging it into Y and you will likely see what the problem is.enum { N = 100 };.staticis redundant in the C++ example.constobjects that are not explicitly declaredexternhave internal linkage anyway.