PDA

View Full Version : Can we have a new contest?



Dual-Catfish
06-30-2002, 11:43 AM
Please?

Prelude
06-30-2002, 07:13 PM
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

golfinguy4
06-30-2002, 07:50 PM
Deleted due to utter crappiness.:D

Note to Self: Have to sleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

Prelude
06-30-2002, 08:02 PM
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

ygfperson
06-30-2002, 11:01 PM
Dual-catfish: do you mean the easy contest?

my entry:


int main() {
int i=0;
long x = 1; //change variable type to any other type
while (x) { x<<=1; i++; }
printf("%d bits",i);
}

unfortuneately it doesn't do floating point types.

Dual-Catfish
07-01-2002, 07:39 AM
I mean either the easy or the hard, I really depends on what they end up being.

ygfperson
07-01-2002, 09:10 AM
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?

Prelude
07-01-2002, 10:34 AM
This is what I had in mind:


#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;
}

>who else agrees with this idea?
Well, if there are no entries, what else can you do? ;)

-Prelude