Unix Programming - Which #define for 32vs64 bit

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2005 > Which #define for 32vs64 bit





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Which #define for 32vs64 bit
Billy Patton

2005-05-01, 6:21 pm

I have a problem where warnings occur in my compilation
I compile on linux and solaris using gcc 3.4.1
Here is the define in question:

#define THROW(msg) { \
sprintf(thr_buf,"(%s,%s,%ld) : %s",__FILE__,__FUNCTION__,__LINE__,msg);
throw(thr_buf); }

THe problem is is the __LINE__
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, b-patton@ti.com
Richard Kettlewell

2005-05-01, 6:21 pm

Billy Patton <bpatton@ti.com> writes:
> I have a problem where warnings occur in my compilation
> I compile on linux and solaris using gcc 3.4.1
> Here is the define in question:
>
> #define THROW(msg) { \
> sprintf(thr_buf,"(%s,%s,%ld) :
> %s",__FILE__,__FUNCTION__,__LINE__,msg); throw(thr_buf); }
>
> THe problem is is the __LINE__


__LINE__ expands to 'an integer constant', it is not guaranteed to be
a long.

--
http://www.greenend.org.uk/rjk/
Måns Rullgård

2005-05-01, 6:21 pm

Billy Patton <bpatton@ti.com> writes:

> I have a problem where warnings occur in my compilation
> I compile on linux and solaris using gcc 3.4.1
> Here is the define in question:
>
> #define THROW(msg) { \
> sprintf(thr_buf,"(%s,%s,%ld) :
> %s",__FILE__,__FUNCTION__,__LINE__,msg); throw(thr_buf); }


Make that format specifier just %d.

--
Måns Rullgård
mru@inprovide.com
David Resnick

2005-05-01, 6:21 pm


Richard Kettlewell wrote:
> Billy Patton <bpatton@ti.com> writes:
>
> __LINE__ expands to 'an integer constant', it is not guaranteed to be
> a long.
>
> --
> http://www.greenend.org.uk/rjk/


So what is the solution? The range for line number is 0 to 2147483647,
at least in C as settable by the #line directive. That could be
greater than INT_MAX. I guess a cast (ugh) is in order, as in
(long)__LINE__?

-David

Richard Kettlewell

2005-05-01, 6:21 pm

"David Resnick" <lndresnick@gmail.com> writes:
> Richard Kettlewell wrote:


>
> So what is the solution? The range for line number is 0 to
> 2147483647, at least in C as settable by the #line directive. That
> could be greater than INT_MAX. I guess a cast (ugh) is in order, as
> in (long)__LINE__?


If you want to use %ld then yes you have to explicitly convert to
long.

If you want to use %d then you can avoid the cast but you will get
into trouble if you have source files with more than INT_MAX lines.

Given this is comp.unix.programmer that becomes a question about how
many UNIX implementations have 16-bit ints (and whether you care about
those that do).

--
http://www.greenend.org.uk/rjk/
Alex Colvin

2005-05-01, 6:21 pm

>So what is the solution? The range for line number is 0 to 2147483647,
>at least in C as settable by the #line directive. That could be
>greater than INT_MAX. I guess a cast (ugh) is in order, as in
>(long)__LINE__?


try "%u"?

--
mac the naïf
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com