Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Writing C90 compatible code

Reply
Thread Tools

Writing C90 compatible code

 
 
jacob navia
Guest
Posts: n/a
 
      06-13-2010
I am releasing the first version of the container library this week.
I have 2 problems to solve, where I would appreciate your help

(1): long long doesn't exist in C90. Is there a way of circumventing
that? How could I detect at compile time if long long is supported?
In any way I can always publish the code so that C90 works in 32 bits
only. People that need 64 bits would use a 64 bit compiler.

(2) The"%z" specifier doesn't exist in C90. Is there any work around?

My command line under UNIX is:

gcc -g -Wno-pointer-sign -DUNIX -Wall -pedantic -c -o foo.o foo.c


Thanks
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      06-13-2010
jacob navia <(E-Mail Removed)> writes:

> (1): long long doesn't exist in C90. Is there a way of circumventing
> that? How could I detect at compile time if long long is supported?
> In any way I can always publish the code so that C90 works in 32 bits
> only. People that need 64 bits would use a 64 bit compiler.


#include <limits.h>

#ifdef LLONG_MAX
....
#endif

> (2) The"%z" specifier doesn't exist in C90. Is there any work around?


printf("%lu", (unsigned long) sizeof (...));
--
"Programmers have the right to be ignorant of many details of your code
and still make reasonable changes."
--Kernighan and Plauger, _Software Tools_
 
Reply With Quote
 
 
 
 
Nick
Guest
Posts: n/a
 
      06-13-2010
jacob navia <(E-Mail Removed)> writes:

> I am releasing the first version of the container library this week.
> I have 2 problems to solve, where I would appreciate your help
>
> (1): long long doesn't exist in C90. Is there a way of circumventing
> that? How could I detect at compile time if long long is supported?
> In any way I can always publish the code so that C90 works in 32 bits
> only. People that need 64 bits would use a 64 bit compiler.


Don't confuse "long long" and 64 bits. It really is possible for
something to be 64 bits long and not a long long. Or a long. Or even,
IIRC, an int.

I'd use a bit of pre-compile build magic with a very small program to
see if "long long" can compile (the way autoconf does things), and
probably printing of some sizeofs, then generate an appropriate header
file that gets included by each part.

> (2) The"%z" specifier doesn't exist in C90. Is there any work around?


The usual thing to do is to use ul and a cast for good measure. It
won't work if you have - say - 32 bit longs and a single object bigger
than that of course. Again, though, you can see if you have ull in your
pre-compilation jiggery-pokery.
--
Online waterways route planner | http://canalplan.eu
Plan trips, see photos, check facilities | http://canalplan.org.uk
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      06-13-2010
Nick <(E-Mail Removed)> writes:

> jacob navia <(E-Mail Removed)> writes:
>> (2) The"%z" specifier doesn't exist in C90. Is there any work around?

>
> The usual thing to do is to use ul and a cast for good measure. It
> won't work if you have - say - 32 bit longs and a single object bigger
> than that of course. [...]


It doesn't make much sense for a C90 implementation to have
32-bit longs but objects bigger than 2^32-1 bytes.
--
Just another C hacker.
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      06-13-2010
Ben Pfaff a écrit :
>
> #include <limits.h>
>
> #ifdef LLONG_MAX
> ...
> #endif
>
>> (2) The"%z" specifier doesn't exist in C90. Is there any work around?

>
> printf("%lu", (unsigned long) sizeof (...));


That looks quite reasonable. Thanks.
 
Reply With Quote
 
Nick
Guest
Posts: n/a
 
      06-13-2010
http://www.velocityreviews.com/forums/(E-Mail Removed) (Ben Pfaff) writes:

> Nick <(E-Mail Removed)> writes:
>
>> jacob navia <(E-Mail Removed)> writes:
>>> (2) The"%z" specifier doesn't exist in C90. Is there any work around?

>>
>> The usual thing to do is to use ul and a cast for good measure. It
>> won't work if you have - say - 32 bit longs and a single object bigger
>> than that of course. [...]

>
> It doesn't make much sense for a C90 implementation to have
> 32-bit longs but objects bigger than 2^32-1 bytes.


You are, of course, right.

OTOH, I bet there are non-standard dialects out there that had long long
but no %z qualifier. On those size_t could be an unsigned long long and
they could support such large objects.

I'm pretty sure long long was codifying existing practice.
--
Online waterways route planner | http://canalplan.eu
Plan trips, see photos, check facilities | http://canalplan.org.uk
 
Reply With Quote
 
Nobody
Guest
Posts: n/a
 
      06-13-2010
On Sun, 13 Jun 2010 10:01:47 -0700, Ben Pfaff wrote:

> It doesn't make much sense for a C90 implementation to have
> 32-bit longs but objects bigger than 2^32-1 bytes.


Tell that to Microsoft. Win64 has a 32-bit "long" for compatibility with
Win32.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-13-2010
Nobody <(E-Mail Removed)> writes:
> On Sun, 13 Jun 2010 10:01:47 -0700, Ben Pfaff wrote:
>
>> It doesn't make much sense for a C90 implementation to have
>> 32-bit longs but objects bigger than 2^32-1 bytes.

>
> Tell that to Microsoft. Win64 has a 32-bit "long" for compatibility with
> Win32.


Ok.

Hey, Microsoft, it doesn't make much sense for a C90 implementation to
have 32-bit longs but objects bigger than 2^32-1 bytes.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
FredK
Guest
Posts: n/a
 
      06-13-2010

"Keith Thompson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Nobody <(E-Mail Removed)> writes:
>> On Sun, 13 Jun 2010 10:01:47 -0700, Ben Pfaff wrote:
>>
>>> It doesn't make much sense for a C90 implementation to have
>>> 32-bit longs but objects bigger than 2^32-1 bytes.

>>
>> Tell that to Microsoft. Win64 has a 32-bit "long" for compatibility with
>> Win32.

>
> Ok.
>
> Hey, Microsoft, it doesn't make much sense for a C90 implementation to
> have 32-bit longs but objects bigger than 2^32-1 bytes.
>


Nonsense, from a code compatability standpoint, it makes perfect sense - and
MS is not alone in this regard.



 
Reply With Quote
 
Tom St Denis
Guest
Posts: n/a
 
      06-14-2010
On Jun 13, 7:09*pm, "FredK" <(E-Mail Removed)> wrote:
> "Keith Thompson" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> > Nobody <(E-Mail Removed)> writes:
> >> On Sun, 13 Jun 2010 10:01:47 -0700, Ben Pfaff wrote:

>
> >>> It doesn't make much sense for a C90 implementation to have
> >>> 32-bit longs but objects bigger than 2^32-1 bytes.

>
> >> Tell that to Microsoft. Win64 has a 32-bit "long" for compatibility with
> >> Win32.

>
> > Ok.

>
> > Hey, Microsoft, it doesn't make much sense for a C90 implementation to
> > have 32-bit longs but objects bigger than 2^32-1 bytes.

>
> Nonsense, from a code compatability standpoint, it makes perfect sense - and
> MS is not alone in this regard.


/rant

Only if they were compatible with a) their own spec and b) a real
standard ...

Tom
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing backwards compatible code Steven D'Aprano Python 14 04-24-2006 01:12 PM
making ie compatible code firefox compatible using Greasemonkey? pantagruel Javascript 0 02-17-2006 02:26 PM
Poor quality of lunar images with 20D/C90 jess Digital Photography 45 10-03-2005 03:08 AM
Difference in horizontal and vertical resolution: 20D, Canon zoom, Celestron C90 jess Digital Photography 11 10-03-2005 12:04 AM
Is these functions C90 and/or C99 ? Bernard C Programming 3 06-24-2004 12:45 AM



Advertisments