Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Comparison of ptrdiff_t

Reply
Thread Tools

Re: Comparison of ptrdiff_t

 
 
Alan Gillespie
Guest
Posts: n/a
 
      07-09-2003
pete <> wrote in message news:<>...
> Alan Gillespie wrote:
> >
> > > > > unsigned char *src, *end;
> > > > > size_t bufsiz;
> > > > > ...

> > :
> > :
> > :
> > >
> > > If bufsiz is of type ptrdiff_t, then the expression
> > > ((end - src) > bufsiz)
> > > is valid as long as end and src point to the same object,
> > > or one byte past.
> > >

> >
> > A pedant would say you mean one "char" past.
> > The standard leaves the precise
> > size of a char to the implementation.

>
> Pedant that I am,
> I say that you don't know what you're talking about.
>
> N869
> 6.5.3.4 The sizeof operator
> Semantics
> [#3]
> When applied to an operand that has type char, unsigned char,
> or signed char, (or a qualified version thereof) the result is 1.


That is defining the sizeof operator, not the size of a char.

The sizeof operator gives the size of its operand in chars, not bytes.
Standard C has no notion of a byte.

Now who doesn't know what he's talking about?
 
Reply With Quote
 
 
 
 
Alan Gillespie
Guest
Posts: n/a
 
      07-09-2003
Micah Cowan <> wrote in message news:<>...
> "Alan Gillespie" <> writes:
>
> > > > > unsigned char *src, *end;
> > > > > size_t bufsiz;
> > > > > ...

> > :
> > :
> > :
> > >
> > > If bufsiz is of type ptrdiff_t, then the expression
> > > ((end - src) > bufsiz)
> > > is valid as long as end and src point to the same object,
> > > or one byte past.
> > >

> >
> > A pedant would say you mean one "char" past. The standard leaves the precise
> > size of a char to the implementation.

>
> Yes, the precise size of a char... in *bits*. A char (or unsigned
> char) is *always* one byte in size, regardless of how many bits may be
> in a byte.
>
> -Micah


Not quite. sizeof(char) always gives 1 because the sizeof operator is
defined that way - it gives the size of its operand in chars.

A byte is /always/ 8 bits, but that has nothing to do with C. C has no
notion of a byte.
 
Reply With Quote
 
 
 
 
Alan Gillespie
Guest
Posts: n/a
 
      07-09-2003
> My opinion, is that a warning about signed/unsigned comparison
> is a good warning, and I wouldn't lower my compiler's warning
> level to avoid it.


You're right not to lower the warning threshold. I wish more people
thought like that.
 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      07-09-2003
Alan Gillespie wrote:
>
> pete <> wrote in message news:<>...
> > Alan Gillespie wrote:
> > >
> > > > > > unsigned char *src, *end;
> > > > > > size_t bufsiz;
> > > > > > ...
> > > :
> > > :
> > > :
> > > >
> > > > If bufsiz is of type ptrdiff_t, then the expression
> > > > ((end - src) > bufsiz)
> > > > is valid as long as end and src point to the same object,
> > > > or one byte past.
> > > >
> > >
> > > A pedant would say you mean one "char" past.
> > > The standard leaves the precise
> > > size of a char to the implementation.

> >
> > Pedant that I am,
> > I say that you don't know what you're talking about.
> >
> > N869
> > 6.5.3.4 The sizeof operator
> > Semantics
> > [#3]
> > When applied to an operand that has type char, unsigned char,
> > or signed char, (or a qualified version thereof) the result is 1.

>
> That is defining the sizeof operator, not the size of a char.
>
> The sizeof operator gives the size of its operand in chars, not bytes.
> Standard C has no notion of a byte.
>
> Now who doesn't know what he's talking about?


You, and worse today than yesterday.

Richard Bos made a post 5 minutes ago,
in response to your post in the
Re:size of array??
thread, quoting N869 and explaining what Micah Cowan has already
explained to you in this thread.

I always avoid making posts which make it appear as though
it is substantially easier for me to post than to:
1 access a copy of the standard
2 acess a compiler

http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/
 
Reply With Quote
 
Zoran Cutura
Guest
Posts: n/a
 
      07-09-2003
Alan Gillespie <> wrote:
> Micah Cowan <> wrote in message news:<>...
>> "Alan Gillespie" <> writes:
>>
>> > > > > unsigned char *src, *end;
>> > > > > size_t bufsiz;
>> > > > > ...
>> > :
>> > :
>> > :
>> > >
>> > > If bufsiz is of type ptrdiff_t, then the expression
>> > > ((end - src) > bufsiz)
>> > > is valid as long as end and src point to the same object,
>> > > or one byte past.
>> > >
>> >
>> > A pedant would say you mean one "char" past. The standard leaves the precise
>> > size of a char to the implementation.

>>
>> Yes, the precise size of a char... in *bits*. A char (or unsigned
>> char) is *always* one byte in size, regardless of how many bits may be
>> in a byte.
>>
>> -Micah

>
> Not quite. sizeof(char) always gives 1 because the sizeof operator is
> defined that way - it gives the size of its operand in chars.
>
> A byte is /always/ 8 bits, but that has nothing to do with C. C has no
> notion of a byte.


Sorry Alan,

but you're wrong. Look what ISO/IEC 9899:1999 has to say about this:

3.6
1 *byte* addressable unit of data storage large enough to hold any
member of the basic character set of the execution environment
2 NOTE 1 It is possible to express the address of each individual byte
of an object uniquely.
3 NOTE 2 A byte is composed of a contiguous sequence of bits, the
number of which is implementationdefined. The least significant bit
is called the low-order bit; the most significant bit is called the
high-order bit.

6.5.3.4 The sizeof operator

2 The sizeof operator yields the size (in bytes) of its operand, ...

3 When applied to an operand that has type char, unsigned char, or
signed char, (or a qualified version thereof) the result is 1.

which implies that "a char is a byte is a char"!


--
Z ()
"LISP is worth learning for the profound enlightenment experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days." -- Eric S. Raymond
 
Reply With Quote
 
Christian Bau
Guest
Posts: n/a
 
      07-09-2003
In article < >,
(Alan Gillespie) wrote:

> pete <> wrote in message
> news:<>...
> > Alan Gillespie wrote:
> > >
> > > > > > unsigned char *src, *end;
> > > > > > size_t bufsiz;
> > > > > > ...
> > > :
> > > :
> > > :
> > > >
> > > > If bufsiz is of type ptrdiff_t, then the expression
> > > > ((end - src) > bufsiz)
> > > > is valid as long as end and src point to the same object,
> > > > or one byte past.
> > > >
> > >
> > > A pedant would say you mean one "char" past.
> > > The standard leaves the precise
> > > size of a char to the implementation.

> >
> > Pedant that I am,
> > I say that you don't know what you're talking about.
> >
> > N869
> > 6.5.3.4 The sizeof operator
> > Semantics
> > [#3]
> > When applied to an operand that has type char, unsigned char,
> > or signed char, (or a qualified version thereof) the result is 1.

>
> That is defining the sizeof operator, not the size of a char.
>
> The sizeof operator gives the size of its operand in chars, not bytes.
> Standard C has no notion of a byte.
>
> Now who doesn't know what he's talking about?


From the C99 Standard:

3.4: byte
addressable unit of data storage large enough to hold any member of the
basic character set of the execution environment
 
Reply With Quote
 
Christian Bau
Guest
Posts: n/a
 
      07-09-2003
In article < >,
(Alan Gillespie) wrote:

> Micah Cowan <> wrote in message
> news:<>...
> > "Alan Gillespie" <> writes:
> >
> > > > > > unsigned char *src, *end;
> > > > > > size_t bufsiz;
> > > > > > ...
> > > :
> > > :
> > > :
> > > >
> > > > If bufsiz is of type ptrdiff_t, then the expression
> > > > ((end - src) > bufsiz)
> > > > is valid as long as end and src point to the same object,
> > > > or one byte past.
> > > >
> > >
> > > A pedant would say you mean one "char" past. The standard leaves the
> > > precise
> > > size of a char to the implementation.

> >
> > Yes, the precise size of a char... in *bits*. A char (or unsigned
> > char) is *always* one byte in size, regardless of how many bits may be
> > in a byte.
> >
> > -Micah

>
> Not quite. sizeof(char) always gives 1 because the sizeof operator is
> defined that way - it gives the size of its operand in chars.
>
> A byte is /always/ 8 bits, but that has nothing to do with C. C has no
> notion of a byte.


You are confusing bytes with octets.
 
Reply With Quote
 
Micah Cowan
Guest
Posts: n/a
 
      07-10-2003
(Alan Gillespie) writes:

> Micah Cowan <> wrote in message news:<>...
> > "Alan Gillespie" <> writes:
> >
> > > > > > unsigned char *src, *end;
> > > > > > size_t bufsiz;
> > > > > > ...
> > > :
> > > :
> > > :
> > > >
> > > > If bufsiz is of type ptrdiff_t, then the expression
> > > > ((end - src) > bufsiz)
> > > > is valid as long as end and src point to the same object,
> > > > or one byte past.
> > > >
> > >
> > > A pedant would say you mean one "char" past. The standard leaves the precise
> > > size of a char to the implementation.

> >
> > Yes, the precise size of a char... in *bits*. A char (or unsigned
> > char) is *always* one byte in size, regardless of how many bits may be
> > in a byte.
> >
> > -Micah

>
> Not quite. sizeof(char) always gives 1 because the sizeof operator is
> defined that way - it gives the size of its operand in chars.
>
> A byte is /always/ 8 bits, but that has nothing to do with C. C has no
> notion of a byte.


Prepare to be corrected.

Read the C standard (or at least a draft) before correcting me,
please.

-Micah
 
Reply With Quote
 
Finny Merrill
Guest
Posts: n/a
 
      07-10-2003
"Alan Gillespie" <> wrote in
news:bee4oq$m7q$:

> A pedant would say you mean one "char" past. The standard leaves the
> precise size of a char to the implementation.
>


The standard also defines "byte" to mean the size of a char. Therefore, by
definition, a char and a byte are the same size.
 
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
c pointers (ptrdiff_t) andy_dufresne C Programming 1 12-01-2005 10:40 PM
c pointers (ptrdiff_t) andy_dufresne C Programming 3 12-01-2005 02:52 PM
question posted on another forum (ptrdiff_t) akshayrao@gmail.com C Programming 2 11-30-2005 09:39 PM
ptrdiff_t Stefan Ram C Programming 13 12-18-2004 06:14 PM
Re: Comparison of ptrdiff_t Mike Wahler C Programming 0 07-05-2003 01:56 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57