Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > va_arg and short

Reply
Thread Tools

va_arg and short

 
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      11-24-2003
Micah Cowan wrote:

> glen herrmannsfeldt <(E-Mail Removed)> writes:
>
>
>>How do you make a constant of type size_t?

>
>
> (size_t) 100


I was thinking about (size_t) 1000000 or maybe (size_t) 3000000000

but you don't know if INT_MAX or even LONG_MAX is big enough.

Maybe an S suffix for size_t constants?

-- glen

 
Reply With Quote
 
 
 
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      11-24-2003
Richard Tobin wrote:

> In article <(E-Mail Removed)>,
> CBFalconer <(E-Mail Removed)> wrote:


>>Of course. You see it every day on your garden variety x86
>>machines. Every pointer involves a segment register value, all of
>>which just happen to be set the same, and thus effectively
>>ignored.


> That's silly. You might as well say that all pointers include the
> page table. The implementation of dereferencing pointers involves the
> segment registers, but they are not part of the pointer. If they were,
> you'd be able to alter a pointer to include a different segment
> register - by abuse of pointers to pointers, or by using a debugger -
> and you can't.


Well, there are compilers that support 48 bit pointers, with a segment
selector and 32 bit offset. They are rare, though, and I don't think
support huge model where overflowing offset increments the selector.

With the AMD 64 bit processors things may change.

-- glen

 
Reply With Quote
 
 
 
 
Andreas Schwab
Guest
Posts: n/a
 
      11-24-2003
glen herrmannsfeldt <(E-Mail Removed)> writes:

> Micah Cowan wrote:
>
>> glen herrmannsfeldt <(E-Mail Removed)> writes:
>>
>>>How do you make a constant of type size_t?

>> (size_t) 100

>
> I was thinking about (size_t) 1000000 or maybe (size_t) 3000000000
>
> but you don't know if INT_MAX or even LONG_MAX is big enough.


(size_t) 1000 * (size_t) 1000

Andreas.

--
Andreas Schwab, SuSE Labs, http://www.velocityreviews.com/forums/(E-Mail Removed)
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      11-24-2003
In <(E-Mail Removed)> CBFalconer <(E-Mail Removed)> writes:

>glen herrmannsfeldt wrote:
>>

>... snip ...
>>
>> Can an implementation have 64 bit pointers, but no integer type
>> longer than 32 bits?

>
>Of course. You see it every day on your garden variety x86
>machines. Every pointer involves a segment register value, all of
>which just happen to be set the same, and thus effectively
>ignored.


In which case, they are not part of the pointer value, as far as any
correct C program is concerned.

It's the same with the tiny and small memory models of the 8086: they
had 16-bit pointers, although the processor used 20-bit addresses.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      11-24-2003
In <VZhwb.219482$9E1.1201461@attbi_s52> glen herrmannsfeldt <(E-Mail Removed)> writes:

>I was thinking about (size_t) 1000000 or maybe (size_t) 3000000000
>
>but you don't know if INT_MAX or even LONG_MAX is big enough.


It doesn't matter: the type of 1000000 or 3000000000 is automatically
chosen by the compiler to accomodate the value of the constant, if such
a type exists:

5 The type of an integer constant is the first of the corresponding
list in which its value can be represented.

|| |
|| | Octal or Hexadecimal
Suffix || Decimal Constant | Constant
-------------++-----------------------+------------------------
none ||int | int
||long int | unsigned int
||long long int | long int
|| | unsigned long int
|| | long long int
|| | unsigned long long int
-------------++-----------------------+------------------------
u or U ||unsigned int | unsigned int
||unsigned long int | unsigned long int
||unsigned long long int | unsigned long long int
-------------++-----------------------+------------------------
l or L ||long int | long int
||long long int | unsigned long int
|| | long long int
|| | unsigned long long int
-------------++-----------------------+------------------------
Both u or U ||unsigned long int | unsigned long int
and l or L ||unsigned long long int | unsigned long long int
-------------++-----------------------+------------------------
ll or LL ||long long int | long long int
|| | unsigned long long int
-------------++-----------------------+------------------------
Both u or U ||unsigned long long int | unsigned long long int
and ll or LL || |

If an integer constant cannot be represented by any type in
its list, it may have an extended integer type, if the extended
integer type can represent its value. If all of the types in the
list for the constant are signed, the extended integer type shall
be signed. If all of the types in the list for the constant are
unsigned, the extended integer type shall be unsigned. If the
list contains both signed and unsigned types, the extended
integer type may be signed or unsigned.

This effectively guarantees that, if 3000000000000000000000000 is
a supported value for the type size_t, (size_t) 3000000000000000000000000
will give you the right thing, even if there is no standard integer type
that can represent 3000000000000000000000000 (size_t will be an alias for
an extended integer type, in this case).

>Maybe an S suffix for size_t constants?


What problem would such a suffix solve that a cast to size_t wouldn't?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      11-24-2003
In <(E-Mail Removed)> Andreas Schwab <(E-Mail Removed)> writes:

>glen herrmannsfeldt <(E-Mail Removed)> writes:
>
>> Micah Cowan wrote:
>>
>>> glen herrmannsfeldt <(E-Mail Removed)> writes:
>>>
>>>>How do you make a constant of type size_t?
>>> (size_t) 100

>>
>> I was thinking about (size_t) 1000000 or maybe (size_t) 3000000000
>>
>> but you don't know if INT_MAX or even LONG_MAX is big enough.

>
>(size_t) 1000 * (size_t) 1000


Name ONE scenario where (size_t) 1000 * (size_t) 1000 works better than
(size_t) 1000000.

Here's one scenarion where (size_t) 1000 * (size_t) 1000 invokes undefined
behaviour, but (size_t) 1000000 doesn't:

#typedef unsigned short size_t
#define USHRT_MAX 65535
#define INT_MAX 131071

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      11-24-2003
glen herrmannsfeldt wrote:
> Micah Cowan wrote:
> > glen herrmannsfeldt <(E-Mail Removed)> writes:
> >
> >>How do you make a constant of type size_t?

> >
> > (size_t) 100

>
> I was thinking about (size_t) 1000000 or maybe (size_t) 3000000000
>
> but you don't know if INT_MAX or even LONG_MAX is big enough.


I believe size_t is specified to be an integral type, and the
largest integral type is long (in C90) or long long (in C99).

--
Chuck F ((E-Mail Removed)) ((E-Mail Removed))
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      11-24-2003
CBFalconer wrote:
>
> glen herrmannsfeldt wrote:
> > Micah Cowan wrote:
> > > glen herrmannsfeldt <(E-Mail Removed)> writes:
> > >
> > >>How do you make a constant of type size_t?
> > >
> > > (size_t) 100

> >
> > I was thinking about (size_t) 1000000 or maybe (size_t) 3000000000
> >
> > but you don't know if INT_MAX or even LONG_MAX is big enough.

>
> I believe size_t is specified to be an integral type, and the
> largest integral type is long (in C90) or long long (in C99).


size_t is integral, and unsigned as well.

C90 defines nine integer types (plain char plus signed
and unsigned versions of char, short, int, and long). The
list is complete; no implementation-provided extra type is
considered an "integer." Thus, size_t is a synonym for one
of the four or five unsigned types.

C99 adds long long, raising the census of standard
integer types to eleven and the number of standard size_t
candidate types to five or six. But C99 also introduces
optional "extended" integer types, and as far as I can
tell it is permissible for size_t to be an extended type.
In C99, `unsigned long long' might not be wide enough for
all size_t values. `uintmax_t' will work, of course.

--
(E-Mail Removed)
 
Reply With Quote
 
Douglas A. Gwyn
Guest
Posts: n/a
 
      11-24-2003
CBFalconer wrote:
> I believe size_t is specified to be an integral type, and the
> largest integral type is long (in C90) or long long (in C99).


Those are the widest *standard* integer types.
An implementation can also support extended integer types,
and as of C99 we officially permit them to be used for size_t etc.
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      11-24-2003
CBFalconer wrote:
>
> glen herrmannsfeldt wrote:
> > Micah Cowan wrote:
> > > glen herrmannsfeldt <(E-Mail Removed)> writes:
> > >
> > >>How do you make a constant of type size_t?
> > >
> > > (size_t) 100

> >
> > I was thinking about (size_t) 1000000 or maybe (size_t) 3000000000
> >
> > but you don't know if INT_MAX or even LONG_MAX is big enough.

>
> I believe size_t is specified to be an integral type, and the
> largest integral type is long (in C90) or long long (in C99).


More precisely, size_t is specified as being an unsigned integral type.
The largest unsigned integral type is indeed 'unsigned long' in C90, but
it is 'uintmax_t' in C99, which might be larger than 'unsigned long
long'. The only requirements on size_t are UCHAR_MAX<=SIZE_MAX &&
SIZE_MAX<=UINTMAX_MAX.
 
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
Difference of extern short *x and extern short x[]? Andre C Programming 5 07-17-2012 07:38 PM
va_arg... recursion: changing arguments and the using recursion jononanon@googlemail.com C Programming 8 04-26-2012 08:37 PM
Re: va_arg() question Eric Sosman C Programming 1 08-08-2003 12:25 AM
Re: va_arg() question Gordon Burditt C Programming 0 08-07-2003 04:19 PM
variable num args via 'va_arg' Suzanne Vogel C++ 2 07-05-2003 02:19 PM



Advertisments