On Windows XP, unsigned integers are 32 bits. Partition the bits of the
unsigned integer C into 4 8-bit chunks like so:
C = XRGB.
Then
unsigned char* p = &C;
Does
p[0] = X; ?
p[1] = R; ?
p[2] = G; ?
p[3] = B; ?
or
p[0] = B; ?
p[1] = G; ?
p[2] = R; ?
p[3] = X; ? 8 1563
Since you are on a little-endian machine, I believe the answer is #2.
On Fri, 15 Sep 2006, vsgdp wrote:
On Windows XP, unsigned integers are 32 bits. Partition the bits of the
unsigned integer C into 4 8-bit chunks like so:
C = XRGB.
Then
unsigned char* p = &C;
Does
p[0] = X; ?
p[1] = R; ?
p[2] = G; ?
p[3] = B; ?
or
p[0] = B; ?
p[1] = G; ?
p[2] = R; ?
p[3] = X; ?
vsgdp posted:
On Windows XP, unsigned integers are 32 bits.
Depends on your compiler.
Partition the bits of the unsigned integer C into 4 8-bit chunks like
so:
C = XRGB.
Then
unsigned char* p = &C;
Does
p[0] = X; ?
p[1] = R; ?
p[2] = G; ?
p[3] = B; ?
or
p[0] = B; ?
p[1] = G; ?
p[2] = R; ?
p[3] = X; ?
Depends how much crack you smoke, because your code has no basis in C++.
--
Frederick Gotham
On Windows XP, unsigned integers are 32 bits. Partition the bits of the
unsigned integer C into 4 8-bit chunks like so:
C = XRGB.
Then
unsigned char* p = &C;
Does
p[0] = X; p[1] = R; p[2] = G; p[3] = B; ?
or
p[0] = B; p[1] = G; p[2] = R; p[3] = X; ?
Easy enough to check:
unsigned int C = 1;
cout << sizeof(C) << endl;
unsigned char* p = (unsigned char*)&C;
cout << "[0]" << (int)p[0] << "\t";
cout << "[1]" << (int)p[1] << "\t";
cout << "[2]" << (int)p[2] << "\t";
cout << "[3]" << (int)p[3] << endl;
For option 1, the expected output would be
4
[0]0 [1]0 [2]0 [3]1
For option 2:
4
[0]1 [1]0 [2]0 [3]0
(Further testing with C = 256, C = 256 * 256, and C = 256*256*256 would
add to the confidence you get running this.)
Michael
P.S. On my machine, with my compiler, I get option 2.
On Sat, 16 Sep 2006 00:19:27 GMT, Frederick Gotham
<fg*******@SPAM.comwrote in comp.lang.c++:
vsgdp posted:
On Windows XP, unsigned integers are 32 bits.
Depends on your compiler.
Partition the bits of the unsigned integer C into 4 8-bit chunks like
so:
C = XRGB.
Then
unsigned char* p = &C;
Does
p[0] = X; ?
p[1] = R; ?
p[2] = G; ?
p[3] = B; ?
or
p[0] = B; ?
p[1] = G; ?
p[2] = R; ?
p[3] = X; ?
Depends how much crack you smoke, because your code has no basis in C++.
Perhaps you should "read over" your posts, as you claim to "read over"
your code, with the exception of that which you post to usenet.
The OP's code is 100% strictly conforming C, based on the fact that
the implementation has an exact-width 32-bit unsigned integer type
with no padding bits, and CHAR_BIT is 8. The OP specified the former
(and it is true), and while he did not specify the latter, it is true
as well.
Given that those two conditions are satisfied, his code is perfectly
correct, although the result is implementation-defined. Any object in
C++, and I do mean any object, not just PODs, may be examined as an
array of unsigned chars.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Frederick Gotham <fg*******@SPAM.comwrites:
vsgdp posted:
On Windows XP, unsigned integers are 32 bits.
Depends on your compiler.
Uh? On SysV ABI compliant system such as Linux it doesn't. Are you
sure that in the Windows world, there is no such standard?
Can anyone shed light on this?
Jens
Jens Theisen wrote:
Frederick Gotham <fg*******@SPAM.comwrites:
>vsgdp posted:
>>On Windows XP, unsigned integers are 32 bits.
Depends on your compiler.
Uh? On SysV ABI compliant system such as Linux it doesn't. Are you
sure that in the Windows world, there is no such standard?
There is not.
MS publishes an API for system calls, but have no requirements for
apps (or compilers).
Bo Persson
"Bo Persson" <bo*@gmb.dkwrites:
There is not.
MS publishes an API for system calls, but have no requirements for
apps (or compilers).
Clearly a dll and the code that's calling into it must have the same
idea of what's an unsigned int.
So I gather this API they publish is authorative for any compiler
vendor.
Regards,
Jens
"vsgdp" <he***@null.comwrote in message
news:lSGOg.9585$cw.4804@fed1read03...
On Windows XP, unsigned integers are 32 bits. Partition the bits of the
unsigned integer C into 4 8-bit chunks like so:
C = XRGB.
Then
unsigned char* p = &C;
Does
p[0] = X; ?
p[1] = R; ?
p[2] = G; ?
p[3] = B; ?
or
p[0] = B; ?
p[1] = G; ?
p[2] = R; ?
p[3] = X; ?
Why don't you try it and find out? That will tell you what your particular
platform does.
In practice, though, I would avoid writing this kind of code. Instead, I
would look at the problem this way:
What exactly do you mean when you say
C = XRGB
? I am going to assume that if you write
C = 0x01020304;
then you intend for X to be 1, R to be 2, G to be 3, and B to be 4. In that
case, you can write the following:
B = C & 0xff;
C >>= 8;
G = C & 0xff;
C >>=8;
R = C & 0xff;
C >>= 8;
X = C & 0xff;
and you will not have to worry about how your particular platform behaves.
Before you claim that this code will be slower than yours, please measure
it. Your version requires 4 memory references (5 if C is not already in
memory); mine requires none. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brian Blais |
last post by:
Hello,
I saw on a couple of recent posts people saying that casting the return
value of malloc is bad, like:
d=(double *) malloc(50*sizeof(double));
why is this bad? I had always thought...
|
by: Ramesh Tharma |
last post by:
Hi,
Is any one knows what's wrong with the following code, I was told that it
will compile and run but it will crash for some values.
Assume that variables are initilized.
char* c;
long*...
|
by: mr_semantics |
last post by:
I have been reading about the practise of casting values to unsigned
char while using the <ctype.h> functions. For example,
c = toupper ((unsigned char) c);
Now I understand that the standard...
|
by: Alex Vinokur |
last post by:
classes that have virtual methods hold pointer to virtual table as
additional implicit data member. So, sizeof of such classes is sizeof
of all data (as struct-POD) plus 4.
It seems that use of...
|
by: brekehan |
last post by:
I've always been a little sketchy on the differences between static,
dynamic, and reinterpret casting. I am looking to clean up the
following block by using C++ casting instead of the C style...
|
by: Francine.Neary |
last post by:
I've read that you should always cast the argument you pass to
isupper(), isalnum(), etc. to unsigned char, even though their
signature is int is...(int).
This confuses me, for the following...
|
by: sophia.agnes |
last post by:
Hi ,
I was going through peter van der linden's book Expert C programming,
in this book there is a section named "How and why to cast"
the author then says as follows
(float) 3 - it's a...
|
by: alex.j.k2 |
last post by:
Hello all,
I have "PRECISION" defined in the preprocessor code
and it could be int, float or double, but I do not know in the
code what it is.
Now if I want to assign zero to a "PRECISION"...
|
by: Tinkertim |
last post by:
Hi,
I have often wondered if casting the return value of malloc() (or
friends) actually helps anything, recent threads here suggest that it
does not .. so I hope to find out.
For instance :
...
|
by: Alex Vinokur |
last post by:
Hi,
Is it possible to do C++-casting from
const pair<const unsigned char*, size_t>*
to
const pair<unsigned char*, size_t>*
?
Alex Vinokur
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| | |