R
Richard Tobin
[/QUOTE]Maybe I'll look at your posts once you manage a competent use of
English spelling.
I'd say you got bullied something awful at school.
Probably by someone like you.
-- Richard
[/QUOTE]Maybe I'll look at your posts once you manage a competent use of
English spelling.
I'd say you got bullied something awful at school.
I've already started a thread about this but it descended into crap
mostly because of incompetant replies.
I'll be very specific about what I'm asking, so please if you don't
know shit about C or how to code then just stay quiet.
What argument can I give memset in order to set an entire chunk of
memory to all bits 1?
snip
UCHAR_MAX isn't guranteed to fit in an int, but maybe we'll get a
consistent result across all implementations if we use it? I'll have
to look up the rules for signed to unsigned conversions. As far as I
know though, it's something along the lines of:
target = TARGET_TYPE_MAX + 1 - negative_number
~0 is a different value on different systems, depending on the system
used to represent negative numbers.
Any other takers for what we should give memset? I think basically we
need an int value that will convert to UCHAR_MAX on every
implementation? Maybe we might have to delve into determing the number
system via macros, but I'm just thinking out loud. In the end we'd
have:
memset(data, INT_VALUE_THAT_WILL_YIELD_UCHAR_MAX, sizeof data);
Joachim said:signed int has the same sizes as unsigned int, so it does have the same
number of bits, so it would fit. It would not represent the same number
though.
typedef sizet_t unsigned int;
size_t size = (size_t)-1;
is legal, isn't it?
Barry said:The ~ is a bitwise operator, not an arithmetic one. 0 is an int that
must be represented by all bits 0. ~0 must therefore be an int with
all bits 1, regardless of what value it represents.
Since sizeof(int)
must be at least as large as sizeof(char) which is the same as
sizeof(unsigned char),
when ~0 is converted to unsigned char in the
call to memset, the resulting value will have all bits 1 also.
I've already started a thread about this but it descended into crap
mostly because of incompetant replies.
I'll be very specific about what I'm asking, so please if you don't
know shit about C or how to code then just stay quiet.
What argument can I give memset in order to set an entire chunk of
memory to all bits 1?
~0 is a different value on different systems, depending on the system
used to represent negative numbers.
Any other takers for what we should give memset? I think basically we
need an int value that will convert to UCHAR_MAX on every
implementation?
I've already started a thread about this but it descended into crap
mostly because of incompetant replies.
Newgroup responses are worth at least what you pay for them...
I'll be very specific about what I'm asking, so please if you don't
know shit about C or how to code then just stay quiet.
This is a public newsgroup. People can choose for themselves whether
and how to respond. My response is just on the verge of killfiling
you. You can equally choose to killfile those you determine unworthy
of your consideration...
What argument can I give memset in order to set an entire chunk of
memory to all bits 1?
I heard you the first time and answered you, correctly as far as I can
tell, in the previous thread.
[Snip]
~0 is a different value on different systems, depending on the system
used to represent negative numbers.
The standard suggests that you are incorrect here, probably due to you
being confused between numeric and bitwise interpretations of data.
Pete's response to Barry on the other hand suggests I'm confused. Fair
enough, I try to learn from my mistakes...
Well, you can force it in there, so it fits, sort of, not bits are choppedSo the number UCHAR_MAX does not fit into an int. Some other number has
taken its place.
By your argument there is no constant which doesn't fit into an int!
That's a different issue. It's legal, but you wouldn't say that -1 fits
into a size_t, would you?
No.
Conversion to unsigned char isn't a bitwise operation.
Conversion to unsigned char depends on the value of (~0)
rather than on its bit pattern.
In one's complement, (~0) is either zero,
or negative zero, or a trap.
Martin said:An int whose value is -1 will convert to an unsigned char whose
value is UCHAR_MAX, [...]
...actually I just found the following in the Standard:
| The memset function copies the value
| of c (converted to an unsigned char)
| into each of the first n characters
| of the object pointed to by s.
I've only got the 1999 Standard though. Can someone please
confirm whether C89 necessitates the same behaviour?
pete said:(~0) is INT_MIN in sign and magnitude representation.
(~0) is -1 in two's complement representation.
pete:
Is 0 allowed to be represented as negative zero?
What about ~0u?
And then (unsigned char) (int) ~0u as it goes through
memset?
=?iso-2022-kr?q?=1B=24=29CHarald_van_D=0E=29=26=0Fk?= said:No, it isn't. Neither is -0, -1 * 0, -1 + 1, or anything like that. On
the implementations that support negative zeroes at all,
they are only allowed to be generated by bit manipulation,
or operations that already involve another negative zero.
What argument can I give memset in order to set an entire chunk of
memory to all bits 1?
What argument can I give memset in order to set an entire chunk of
memory to all bits 1?
What argument can I give memset in order to set an entire chunk of
memory to all bits 1?
What argument can I give memset in order to set an entire chunk of
memory to all bits 1?
What argument can I give memset in order to set an entire chunk of
memory to all bits 1?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.