2009-07-17, 08:37 PM
Spaz Wrote:No, it's not any easier than the below code. In fact, I think the code below is more explicit about what it's doing and thus easier to read.
Code:(un)signed whatever n = x;
int bitnumber = y;
cout << getbit(n, bitnmber);
setbit(n, bitnumber, true);
Well, I suppose that's based on preference. For example, a Java/C/C++ programmer would most likely scream in pain if he's told to actually write the following:
Code:
int array = makeArray(x);
int pos = y;
cout << get(array, pos);
set(array, pos, z);Code:
int array[x];
int pos = y;
cout << array[pos];
array[pos] = z;But you can't deny that referring to n[y] is shorter than getbit(n, y), and that referring to n[y] when defined within a compiler could be so efficient that it would point directly to that bit in the memory. (getbit and setbit, if defined within a compiler, could do the same thing of course)
Fiel Wrote:Do these programming languages also work on big endian processors? That could make all of this wrong.
I've never thought about that issue, really. That should however be the compiler's, and not the programmers' issue. A piece of uncompiled code shouldn't have to be modified in order to work on another computing system. That should the compilers take care of.

