Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - "Expression must be constant" error within custom widget resource table: (8 Items)
   
"Expression must be constant" error within custom widget resource table  
Hello,

I'm trying to add two new resources to a custom widget, but getting an "expression must be constant" error. 

My resource table looks like this (and this is what the compiler is complaining about):
...
        CQ_ARG_NORMAL_COLOR, Pt_CHANGE_INTERIOR, 0, 
        	Pt_ARG_IS_NUMBER( CqNumberWidget_t, my_normal_color[0] ), 0,
        CQ_ARG_NORMAL_FILL_COLOR, Pt_CHANGE_INTERIOR, 0, 
        	Pt_ARG_IS_NUMBER(CqNumberWidget_t, my_normal_color[1] ), 0, 
...

In the defaults function I set the resource to 
    w->my_normal_color[0] = Pg_GREEN; 
    w->my_normal_color[1] = Pg_TRANSPARENT ; 

And in the header file I define the resource: 

#define CQ_ARG_NORMAL_COLOR 	Pt_RESOURCES( Pt_USER( 2 ), 14 )
#define CQ_ARG_NORMAL_FILL_COLOR 	Pt_RESOURCES( Pt_USER( 2 ), 15 )

/* Widget instance structure */
typedef struct
{
        ...
        int 				my_normal_color[2]; 
        ...

} CqNumberWidget_t;

Any help would be appreciated. 

Thanks,
Elena 
Re: "Expression must be constant" error within custom widget resource table  
Elena,

You need to pass a member name, not its value. The Pt_ARG_IS_NUMBER is defined:

#define Pt_ARG_IS_NUMBER( type, field ) \
		(	(	Pt_STRUCT_SIZEOF( type, field ) == sizeof(long)			\
				?	Pt_ARG_MODE_LONG									\
				:	Pt_STRUCT_SIZEOF( type, field ) == sizeof(short)	\
					?	Pt_ARG_MODE_SHORT								\
					:	Pt_ARG_MODE_CHAR								\
				)														\
		|	offsetof( type, field ) 									\
			)

The offsetof() is giving your an error.

You can do the math yourself, or simply replace your array with two separate members.

-Misha.
Re: "Expression must be constant" error within custom widget resource table  
Misha,

I have other resources listed as integer arrays that don't give any errors using this setup, but ... 

I did what you suggested: 

/* Widget instance structure */
typedef struct
{
...
        int 				my_normal_color0;
        int 				my_normal_color1;  
...
} CqNumberWidget_t;

and gave Pt_ARG_IS_NUMBER the individual integers: 

resource table: 
...
        CQ_ARG_NORMAL_COLOR, Pt_CHANGE-INTERIOR, 0, 
        	Pt_ARG_IS_NUMBER( CqNumberWidget_t, my_normal_color0 ), 0,
        CQ_ARG_NORMAL_FILL_COLOR, Pt_CHANGE_INTERIOR, 0, 
        	Pt_ARG_IS_NUMBER(CqNumberWidget_t, my_normal_color1 ), 0,
.. 

and I still get the same error, "expression must be constant". 

-- Elena 
Re: "Expression must be constant" error within custom widget resource table  
I am not sure. Obviously there is something in these lines that is not constant.
Can you send the entire file to me?
Re: "Expression must be constant" error within custom widget resource table  
Sure. What is the email I should send this to?

Thank you,
Elena 
Re: "Expression must be constant" error within custom widget resource table  
mnefedov at qnx dot com
Re: "Expression must be constant" error within custom widget resource table  
I figured it out, and it was a hard to see typo. 

#define CQ_ARG_NORMAL_COLOR 	Pt_RESOURCES( Pt_USER( 2 ), 14 )
#define CQ_ARG_NORMAL_FILL_COLOR 	Pt_RESOURCES( Pt_USER( 2 ), 15 )

It should be Pt_RESOURCE, not Pt_RESOURCES... 

Thank you for looking into my problem, Misha. 

Elena 
Re: "Expression must be constant" error within custom widget resource table  
Cool :-)