J
joshc
So while I've been programming in C for 5 years now while I was in
school, I only recently started having to worry about portability and
writing C code in conformance with the C standard. I did try to look
through various parts of the standard for my answers, but I didn't find
what I was looking for.
First off, the reason for the following questions are because I want to
know if what I'm about to describe is in conformance with the C99
standard. I want to test if two signed integers have the same 'sign' so
I am XORing them and seeing if the result is positive or zero. I am not
sure if this is in conformance with the standard; my guess is that it
is not because the standard doesn't define how integers are to be
stored, i.e. two's complement, etc.
I confused myself because while the C standard is not supposed to
define the execution environment, a few things made me think. Please
read through my reasoning and help correct any flaws in my thinking.
The standard says that shifting an unsigned or positive integer left is
like a multiplication by 2. Does this mean that if a processor is not a
binary machine, an implementation for that processor will have to
somehow "fake" integers being stored as a binary number? This also got
me into thinking what bitwise operators would mean on processors that
might deal in base-10 for some odd reason or another.
I know this is long, but I know I'm missing some big picture idea here
or some fundamental concept.
Thanks.
school, I only recently started having to worry about portability and
writing C code in conformance with the C standard. I did try to look
through various parts of the standard for my answers, but I didn't find
what I was looking for.
First off, the reason for the following questions are because I want to
know if what I'm about to describe is in conformance with the C99
standard. I want to test if two signed integers have the same 'sign' so
I am XORing them and seeing if the result is positive or zero. I am not
sure if this is in conformance with the standard; my guess is that it
is not because the standard doesn't define how integers are to be
stored, i.e. two's complement, etc.
I confused myself because while the C standard is not supposed to
define the execution environment, a few things made me think. Please
read through my reasoning and help correct any flaws in my thinking.
The standard says that shifting an unsigned or positive integer left is
like a multiplication by 2. Does this mean that if a processor is not a
binary machine, an implementation for that processor will have to
somehow "fake" integers being stored as a binary number? This also got
me into thinking what bitwise operators would mean on processors that
might deal in base-10 for some odd reason or another.
I know this is long, but I know I'm missing some big picture idea here
or some fundamental concept.
Thanks.