[freetds] CS_INT size bug

entropy at freetds.org entropy at freetds.org
Sun Sep 3 20:22:40 EDT 2006


jklowden at schemamania.org wrote:
> On Sun, Sep 03, 2006 at 04:42:12PM -0400, entropy at freetds.org wrote:
>> Norbert Sendetzky wrote:
>>
>>> I'm using a standard 32bit x86 machine.
>>>
>>> The problem I'm facing are lots of warnings when compiling the sybase backend 
>>> of my library (OpenDBX, http://www.linuxnetworks.de/opendbx/) against FreeTDS 
>>> instead of the Sybase ctlib.
>>>
>>> In Sybase' ctlib, CS_INT is defined as "long" and as "int" in FreeTDS which is 
>>> problematic when using printf() functions. This is because of the different 
>>> expectations gcc/printf have when handling "%d" and "%ld" modifiers.
>> The problem is that your code is making assumptions about what type a 
>> CS_INT is.  If it were reasonable for your code to do that, then there 
>> would be no such thing as a CS_INT, and instead it would just be "int" 
>> or "long".
>>
>> The most portable thing your code can do in this case is explicitly cast 
>> to a type, then use the printf(3) format for that type.
> 
> That's good advice from a C perspective.  The application shouldn't assume 
> anything about opaque types.  
> 
>>From the library's perspective, though, maybe we're making a mistake?  We 
> do a bunch of things in the header files -- e.g. use #define instead of enum
> -- just because that's how Sybase did it 20 years ago.  It wouldn't be 
> wrong to change it.  

Not sure what you mean.  In my copy of FreeTDS, CS_INT is a typedef.  I 
don't see how an enum would be helpful.

[550]entropy at zippy:~/freetds/include $ grep CS_INT cstypes.h | head -1
typedef tds_sysdep_int32_type CS_INT;

Even though I don't think it's relevant here, I'm opposed to the idea of 
sweeping changes where we would convert CPP macros to enums.  I don't 
think the religious benefits outweigh the practical lossage, such as 
breaking existing code using #ifdef on those macros.

-- 
Cheers,
entropy



More information about the FreeTDS mailing list