[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
gEDA: Re: struct t_vpi_systf_data
Larry Doolittle wrote:
Steve -
Icarus' vpi_user.h contains the following declaration:
typedef struct t_vpi_systf_data {
PLI_INT32 type;
PLI_INT32 subtype;
char *tfname;
PLI_INT32 (*calltf)(char*);
PLI_INT32 (*compiletf)(char*);
PLI_INT32 (*sizetf)();
char *user_data;
} s_vpi_systf_data, *p_vpi_systf_data;
and a typical code snippet I use to fill in this structure is
s_vpi_systf_data tf_data;
tf_data.type = vpiSysTask;
tf_data.tfname = "$llrf_sysmodel";
tf_data.calltf = sysmodel_calltf;
tf_data.compiletf = sysmodel_compiletf;
tf_data.sizetf = 0;
tf_data.user_data = "$llrf_sysmodel";
I recently turned gcc's warning level up another few notches.
When I add -Wwrite-strings to the mix, gcc barks at the above:
warning: assignment discards qualifiers from pointer target type
This actually makes sense: how am I supposed to know that the routine
that manipulates this data structure (vpi_register_systf) never modifies
foo.tfname or foo.user_data? If it _might_, I need to strdup().
If it is guaranteed not to, the structure member declarations for
tfname and user_data need "const" added.
O Verilog Master, which is the one true path?
The IEEE1364 folks seem to have lacked the practical C programming
experience needed to get things like this right. In fact, the standard
declares tfname to be PLI_BYTE*, which is sheer nonsense. They clearly
did a global substitute on the header file. We will do the right thing
and call it "const char*" which is backwards compatible with 1364.
I've edited my copy of vpi_user.h, so the change will make its
way to CVS in due course. I will consider filing this as a change
request with the IEEE, but it might not fly due to some ancient
C compilers not supporting the const keyword.
The user_data member is a little bit more tricky. It too is not
modified by the VPI. Heck, it really should be "const void*" but
given the way users would tend to use it, that change may cause
more warnings then it fixes.
--
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."