[freetds] tdsstring.c ansi alias problem

Lowden, James K LowdenJK at bernstein.com
Mon May 5 13:24:32 EDT 2003


> From: ZIGLIO Frediano [mailto:Frediano.Ziglio at vodafoneomnitel.it]
> Sent: May 5, 2003 11:55 AM
> > 
> > Where is DSTR_CHAR defined?  I find only a forward 
> > declaration in tds.h.
> 
> Yes, it's true. It's an undefined structure. I use a pointer 
> to undefined structure to be more type safe using C...

Oh.  That's an unusual technique; a comment would have saved us some time.
:-)

> Also in such way I can 
> extend dstring in future (like adding length and buffer size) 
> without breaking source compatibility.

Maybe, maybe not.  You're trading some potential future flexibility for
permanent opacity.  

If you add members to DSTR_CHAR, you're right, it will compile, because of
all the heavy duty casts.  OTOH, you won't get what you want: the buffer
size and length won't be set correctly until you notice the problem -- at
runtime -- and then fix the code.  And adjusting the code was what you're
trying to avoid, yes?  

I think it's better to expose the structure, for clarity, assigning the
pointer obviously, viz:

	typedef struct { char *s } DSTR_CHAR, *DSTR;
	char src[] = "hi";
	DSTR * s;
	/* then ... */
	s->s = src;

because that code can be understood by all compilers and many human beings.


To protect against outsiders peeking into DSTR_CHAR, it can be defined in
tdsstring.c.  
	
If you decide to change DSTR_CHAR, it won't be hard.  The logic and the
structure are both simple.  Am I missing something?  

> I did this to avoid free(dstring) or other wrong usage.
> If "*(char **) s = src;" is not OK perhaps it's a priority 
> problem... *((char**)s) = src should work better.

You're probably right about that.  

Regards, 

--jkl



The information contained in this transmission may contain privileged and
confidential information and is intended only for the use of the person(s)
named above.  If you are not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, any
review, dissemination, distribution or duplication of this communication is
strictly prohibited. If you are not the intended recipient, please contact
the sender immediately by reply e-mail and destroy all copies of the
original message. Please note that we do not accept account orders and/or
instructions by e-mail, and therefore will not be responsible for carrying
out such orders and/or instructions.





More information about the FreeTDS mailing list