LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

debugger tip: typedef enum for better tracing

This is not a question, but a tip to others.  I was so excited about this, that I had to share.

 

For a long time now, I've been using enum lists without typedeffing them.  My variables that used these lists were simply typed as integers.  The consequence of this is that in the debugger, I would see only numeric indexes that I would have to decode myself.  Looked liks this.

 

Definition

 

 

enum
{
	// system commands
	STEP_TYPE_INIT,
	STEP_TYPE_DELAY,
	STEP_TYPE_HV,		
	STEP_TYPE_KV,		
	STEP_TYPE_UA,		
	STEP_TYPE_R,
	
	MAX_STEP_TYPES,
};

Usage 

 

 

typedef struct
{
	int type;
	
	double parameter[MAX_NUM_PARMS];
	
} step_struct;

script_struct script;

script.step[7].type = STEP_TYPE_KV;

 

 

The above looks like this in the debugger, not very helpful.

 

Variables and Call Stack - int.png

 


 

 

 

Now if we simply typedef the enum and change the type of the variable member "type" to that new typdef, we get much easier debugging.

 

 

 

 

Definition

 

 

typedef enum
{
	// system commands
	STEP_TYPE_INIT,
	STEP_TYPE_DELAY,
	STEP_TYPE_HV,		
	STEP_TYPE_KV,		
	STEP_TYPE_UA,		
	STEP_TYPE_R,
	
	MAX_STEP_TYPES,
} steptype_enum;

 

Usage

 

typedef struct
{
	steptype_enum type;
	
	double parameter[MAX_NUM_PARMS];
	
} step_struct;

script_struct script;

script.step[7].type = STEP_TYPE_KV;

 

 

Variables and Call Stack - typedef.png

 

Message 1 of 1
(3,050 Views)