I am trying to extract debug information from a compiled C program with C#, and need to store the global variables.
If I have the variable:
const unsigned char * volatile MyVariable;
the name of the variable will be MyVariable, and the type is unsigned char. what will be const and volatile. Are they part of the type?
I have to represent a variable with a class and I am lost on how to construct it. This is how I have represented it right now:
public class MyVariable
{
public string Name;
public string Type;
public bool IsArray;
public bool IsPointer;
public bool IsConstant;
public bool IsVolatile;
// etc...
public int Size; // in bytes
}
Should I make volatile and const part of the type? What are they? Attributes?
Edit
Sorry I think I did not explained my self correctly. my question should have been how should I construct MyVariable class I know what the const keyword does to a variable and also the volatile. I use the volatile keyword when I create a variable that will be accessed by multiple threads for example.
Anyways so based on the answers I should be constructing my class as:
public class MyVariable
{
public string Name;
public string Type;
public string[] TypeQualifiers;
public int Size; // in bytes
}
where TypeQualifiers will be an array of those keywords (type qualifiers). Thanks a lot for the help.
constandvolatileare both type qualifiers, although they are completely independent.The
constkeyword specifies that the object or variable cannot be changed within the code.The
volatilequalifier declares the data can have its value changed in ways outside the control or detection of the compiler, preventing the compiler from applying any optimizations on the code (such as storing the object’s value in a register rather than the memory, where it may have changed).A variable which is both
constandvolatilemeans that it is guaranteed not to be changed in the current code, but that does not mean that it cannot be changed externally.EDIT: As a sidenote,
unsignedis a type modifiers in C, just likesignedandlong.I suggest that you also have independent type fields such as
IsSigned,IsUnsignedandIsLongin addition to the type itself (int,char, etc…).