interesting foo question (CHAR_BITS == 12)

H

Hans Schneider

char the_case = 42;

void foo(char *x)
{
*x = *x - 1;
}

int main(void)
{
foo(&the_case);
}

42 bottles of beer in the_case, 42 bottles of beer
=> you take its address and pass it to foo()
=> 41 bottles of beer in the_case.

Assuming (CHAR_BITS == 12), what is the next step?
 
E

Eric Sosman

Hans said:
char the_case = 42;

void foo(char *x)
{
*x = *x - 1;
}

int main(void)
{
foo(&the_case);
}

42 bottles of beer in the_case, 42 bottles of beer
=> you take its address and pass it to foo()
=> 41 bottles of beer in the_case.

Assuming (CHAR_BITS == 12), what is the next step?

What's CHAR_BITS? Well, no matter: Regardless of what
it is, the program returns control to its environment, with
a termination status of zero (C99) or undetermined (C90).

... and why do you call this question "interesting?"
Seems to me about as uninteresting as charred bits.
 
C

CBFalconer

Hans said:
char the_case = 42;

void foo(char *x) {
*x = *x - 1;
}

int main(void) {
foo(&the_case);
}

42 bottles of beer in the_case, 42 bottles of beer
=> you take its address and pass it to foo()
=> 41 bottles of beer in the_case.

Assuming (CHAR_BITS == 12), what is the next step?

Obviously revise main to read:

int main(void) {
while (the_case) foo(&the_case);
return the_case;
}

and it still doesn't need <stdio.h> !!!!!
 
A

Army1987

Walter said:
It depends upon whether char is signed or unsigned.
Why? Both 42 and 41 are guaranteed to fit into any existing real type,
including signed char, and regardless of CHAR_BIT
 
M

Mark Bluemel

Hans said:
char the_case = 42;

void foo(char *x)
{
*x = *x - 1;
}

int main(void)
{
foo(&the_case);
}

42 bottles of beer in the_case, 42 bottles of beer
=> you take its address and pass it to foo()
=> 41 bottles of beer in the_case.

Assuming (CHAR_BITS == 12), what is the next step?

I'm obviously thick, but - what is he on about?
 
J

J. J. Farrell

Hans said:
char the_case = 42;

void foo(char *x)
{
*x = *x - 1;
}

int main(void)
{
foo(&the_case);
}

42 bottles of beer in the_case, 42 bottles of beer
=> you take its address and pass it to foo()
=> 41 bottles of beer in the_case.

Assuming (CHAR_BITS == 12), what is the next step?

Reach for a bottle opener before any more disappear.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top