Please?
Printable View
Please?
Sure, come up with a way to get the size of a variable without the sizeof operator. The first person to do it gains the admiration of those who didn't do it first. ;)
-Prelude
Deleted due to utter crappiness.:D
Note to Self: Have to sleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
And did you test this at all? Once I fixed the syntax errors, all it does is loop infinitely. Here's a hint: The answer is simpler than you think (one-liner).
-Prelude
Dual-catfish: do you mean the easy contest?
my entry:
unfortuneately it doesn't do floating point types.Code:int main() {
int i=0;
long x = 1; //change variable type to any other type
while (x) { x<<=1; i++; }
printf("%d bits",i);
}
I mean either the easy or the hard, I really depends on what they end up being.
i could be persuaded to change the easy if no-one signs up. but the hard one is already locked in stone.
i'll probably need to hold a poll and restart the easy contest under the new topic if there's a lack of contestants. the two runner-up entries are the bitwise calculator and the slot machine.
who else agrees with this idea?
This is what I had in mind:
>who else agrees with this idea?Code:#include <stdio.h>
#define SIZEOF(x) (char *)(&x + 1) - (char *)&x
struct test
{
int a, b, c, d;
float f;
};
int main ( void )
{
int i;
char c;
float f;
double d;
char *a = "This is a test";
char b[] = "This is a test";
struct test s;
printf ( "int: %d\nchar: %d\nfloat: %d\ndouble: %d\n"
"char *: %d\narray: %d\nstruct: %d\n\n",
SIZEOF(i), SIZEOF(c), SIZEOF(f), SIZEOF(d),
SIZEOF(a), SIZEOF(b), SIZEOF(s) );
printf ( "int: %u\nchar: %u\nfloat: %u\ndouble: %u\n"
"char *: %u\narray: %u\nstruct: %u\n\n",
sizeof(i), sizeof(c), sizeof(f), sizeof(d),
sizeof(a), sizeof(b), sizeof(s) );
return 0;
}
Well, if there are no entries, what else can you do? ;)
-Prelude