Limit scope of #define
- by Ujjwal Singh
What is the correct strategy to limit the scope of #define and avoid unwarrented token collisions.
In the following configuration:
Main.c
# include "Utility_1.h"
# include "Utility_2.h"
VOID Utility() // Was written without knowing of: Utility_1 & Utility_2
{
const UINT ZERO = 0;
}
VOID Main()
{
...
}
// Collision; for Line:5 Compiler does not indicate what replaced
Utility_1.h
# define ZERO "Zero"
# define ONE "One"
BOOL Utility_1();
Utility_2.h
# define ZERO '0'
# define ONE '1'
BOOL Utility_2();
Utility_2.c
# include "Utility_2.h"
BOOL Utility_2()
{
// Using: ZERO & ONE
}
//Collision: Character Literal replaced with String
{Edit} Note: This is supposed to be a generic quesition so do not limit yourself to enum or other defined types. i.e. What to do when: I MUST USE #define
Please comment on my proposed solution below.. _