On Tue, 07 Nov 2006 14:39:43 -0600, Kenneth Lantrip
<bo********@cmaaccess.comwrote in comp.lang.c:
Im trying to learn a little more about C compilers.
Im trying to work with 64 bit numbers (integers) with the gcc compiler
in linux (ubuntu). I need to know how to make use of 64 bit numbers.
Make up your mind, are you trying to learn about 64 bit integers, or
about C compilers?
My test program as follows:
-----------------------------------------------------------------
#include <ncurses.h>
#define sleep(x) usleep(x * 1000) // adjust sleep functions to
milliseconds
typedef unsigned char byte; // values are 0-255
#define wlen 43 // how many bits long we are
interested in
int Int2Bin(int x, byte *y) {
int i, j;
y += wlen; *y-- = 0; j = 0;
for (i = 0; i < wlen; i++) {
*y-- = 48 + (x & 1);
Don't do what you did in the line above. It is both absolutely
horrible and absolutely unnecessary. You have placed a "magic number"
directly in the code. Someone reading this code some day might spend
hours scratching his/her head trying to figure out what the 48 is for.
The number of hours you worked last week? The number of cups of
coffee you drank before lunch? The number of lines on a page? The
number of gray hairs you developed working on this code?
Now I happen to have looked into my crystal ball and divined the fact
that you are using 48 as the numeric code for the ASCII '0' character.
Which means that your code is guaranteed to fail if it is ever ported
to a platform that uses a different character set.
And it's totally unnecessary. All you need to do here is replace 48
with '0'. Then it will work on any platform what a conforming C
compiler now and forever, no matter what character set it uses. And
of course, it tells a reader of your program exactly what is going on,
so he/she won't have to wonder if 48 is the number of pimples on your
butt.
if (x & 1) j = i + 1;
x >>= 1;
}
return j;
}
int CountOnes(byte *x) {
int i;
i = 0;
do {
i += 1 & (*x++ == 49);
Oh, there you are, doing it again. You need to nip down to the local
pharmacy for some ointment, it's spreading, you've added another
pimple on the butt.
'1', not 49!
} while (*x != 0);
return i;
}
int main(void) {
static long long Count = 1, t = 0x1FFFFF;
static byte bits[64];
initscr();
noecho();
do {
Int2Bin(t++, bits);
if (CountOnes(bits) == 21) {
printw("%s :: Count = %d\n", bits, Count++);
refresh();
}
} while (t < 0x7FFFFC00000); // error here over long
getch();
endwin();
printf("\nTest program completed successfully.\n\n");
return 0;
}
--------------------------------------------------------
Any help greatly appriciated.
I can't compile your code, because it uses some non-standard headers
and function calls, so don't keep me in suspense. What exactly is the
error message? When asking about such a message, copy the text and
paste it into your post.
--
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