Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Comparing two numbers

49 views
Skip to first unread message

purifier

unread,
Jan 16, 2005, 1:13:20 PM1/16/05
to
The problem is to write a program in 'C' to find the greatest of 2 given
numbers... Easy? huh
here's the catch
do not use 'if' or any conditional statements
if u want it to be a little more tougher you can use the if but this time
no relational operators or any of the predefined functions....

Can someone please help me solve the problem....

Joona I Palaste

unread,
Jan 16, 2005, 1:30:56 PM1/16/05
to
purifier <cnbc...@gmail.com> scribbled the following:

How about (1) doing your homework and (2) speaking English instead of
d00dsp33k?

--
/-- Joona Palaste (pal...@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"All that flower power is no match for my glower power!"
- Montgomery Burns

Mike Wahler

unread,
Jan 16, 2005, 2:46:31 PM1/16/05
to

"purifier" <cnbc...@gmail.com> wrote in message
news:19793998f87506ee...@localhost.talkaboutprogramming.com...

> The problem is to write a program in 'C' to find the greatest of 2 given
> numbers... Easy?

Yup.

> huh
> here's the catch
> do not use 'if' or any conditional statements

Still easy.

> if u want it to be a little more tougher you can use the if but this time
> no relational operators or any of the predefined functions....

Still easy.

> Can someone please help me solve the problem....

OK, I have the solutions all ready to go.

All I need now is your instructor's email
address, and I'll send them off.

-Mike


Mike Wahler

unread,
Jan 16, 2005, 3:14:46 PM1/16/05
to

"Mike Wahler" <mkwa...@mkwahler.net> wrote in message
news:rwzGd.9239$Ii4....@newsread3.news.pas.earthlink.net...

>
> "purifier" <cnbc...@gmail.com> wrote in message
>
news:19793998f87506ee...@localhost.talkaboutprogramming.com...
> > The problem is to write a program in 'C' to find the greatest of 2 given
> > numbers... Easy?

OK, here's a hint for the first form:
0 evaluates to false, 1 evaluates to true.

BTW did your assignment specify whether the inputs
could be equal? If so, what should the result be?

-Mike


Keith Thompson

unread,
Jan 16, 2005, 6:07:29 PM1/16/05
to

Q: How do I drive a screw without using a screwdriver?

A: You don't. Use a screwdriver. That's what they're for.

Now if you actually have some legitimate reason to drive a screw
without using a screwdriver, someone might be able to come up with a
method -- but nobody is going to help you unless you tell them *why*
you want to do such a silly thing, and why your first question isn't
"Where can I find a screwdriver?".

It's the same thing with your question. Without any background, it's
not particularly interesting. If the background is that it's a
homework question, we're not going to do your homework for you. If
it's just a fun little quiz, some of us might be interested, but you
need to say so.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Peter Nilsson

unread,
Jan 16, 2005, 7:01:42 PM1/16/05
to

I read a similar (but more restricted) question very recently
in another forum.

The following uses strtol() to convert arguments on the command
line, and printf() to output the maximum. Otherwise, it doesn't
use any conditional, logical, equality or relational operators,
nor does it use any selection or iteration statements.

Not sure if Google will mangle this...

% type max2.c
typedef unsigned long q1;int printf(const char*,...);long
strtol(const char*,char**,int);q1 q2(q1 q3,q1 q4,q1 q5,q1
q6){return(q5-q6)*(((((q3-q4)&(q4-q3) )+2)/(((q3-q4)&(q4-
q3))+1))-1)+q6;}q1 q7(long q8){return q2(q8,0,q2(q8/2,0,1
,0),0);}q1 q9(long q8){return q2(q8,-1,q2(q8/2,-1,1,q2(q8
/2,0,1,0) ),0);}q1 q10(long);q1 q11(long q8){return 0;}q1
q12(long q8){return 1;}q1 q13(long q8){return q10(q8/2);}
q1 q14(long q8){q1(*q15[])(long)={q12,q13};return q15[q2(
q9(q8),1,0,1)](q8);}q1 q10(long q8){q1(*q15[])(long)={q11
,q14};return q15[ q2(q7(q8),1,0 ,1)](q8);}q1 q17(long q3,
long q4){return q2(q10( q3),1,q2(q10(q4),1,q10(q3-q4),1),
q2(q10(q4),1 ,0,q10(q3-q4 )));}long q18(long q3,long q4){
return q3;}long q19(long q3,long q4){return q4;}long q20(
long q3,long q4){long(*q15[])(long,long)={q19,q18};return
q15[q2(q17(q3,q4),1,0,1)](q3,q4);}long q21(const char*q2)
{return strtol(q2,0,10);}int q22(char **q23){printf("%ld"
"\n",q20(q21(q23[1]),q21(q23[2])));return 0;}int q24(char
**q23){return 0;}int main(int q25,char**q23){int(*q15[])(
char**)={q24,q22};return q15[q2(q25,3,1,0)](q23);}

% gcc -ansi -pedantic max2.c -o max2.exe

% max2 -5 42
42

%

--
Peter

purifier

unread,
Jan 16, 2005, 9:22:36 PM1/16/05
to
It's a real sad thing to know, Sir... I didn't expect that my post would
make you think that it was my homework... I'm an Electronics Engineer, but
i'm interested a lot in programming... One of my friends asked me this
question in a mail. I just pasted that mail here... For your information i
even said "Can you please help me solve the problem" Why would I say huh
and all kinds of stuff and then ask people to solve the problem? I could
have directly given the problem...
Anyway, Sorry if i mislead you guys... Thank you for the replies.. Atleast
if possible, please give me some ideas...
Thank You

Nick Austin

unread,
Jan 17, 2005, 12:32:53 AM1/17/05
to
On 16 Jan 2005 16:01:42 -0800, "Peter Nilsson" <ai...@acay.com.au>
wrote:

[...]


>The following uses strtol() to convert arguments on the command
>line, and printf() to output the maximum. Otherwise, it doesn't
>use any conditional, logical, equality or relational operators,
>nor does it use any selection or iteration statements.

[...]
>typedef unsigned long q1;


>q1 q2(q1 q3,q1 q4,q1 q5,q1 >q6)
>{
> return(q5-q6)*(((((q3-q4)&(q4-q3) )+2)/(((q3-q4)&(q4-q3))+1))-1)+q6;
>}

I don't think that's portable, namely the use of the bitwise operator:

( q3 - q4 ) & ( q4 - q3 )

It seems to me that it assumes twos compliment and could give the
wrong answer on other architectures.

Nick.

Mike Wahler

unread,
Jan 17, 2005, 1:29:05 AM1/17/05
to

"purifier" <cnbc...@gmail.com> wrote in message
news:8a6984c70eddf0d5...@localhost.talkaboutprogramming.com...

I gave you one good clue already:

0 evaluates to false, 1 evalutates to true.

Another:

0 + x == x

-Mike


infobahn

unread,
Jan 17, 2005, 2:06:01 AM1/17/05
to
purifier wrote:
>
> It's a real sad thing to know, Sir... I didn't expect that my post would
> make you think that it was my homework... I'm an Electronics Engineer, but
> i'm interested a lot in programming...

Then you shouldn't have any trouble deriving a solution yourself.

> Anyway, Sorry if i mislead you guys... Thank you for the replies.. Atleast
> if possible, please give me some ideas...

Here are some hints: in C, you can turn an expression into a 0 or a 1
using !!(expression), and you can put "first number is bigger" and
"second number is bigger" into an array like this:

char *bigger[] =
{
"first number is bigger",
"second number is bigger"
};

You can demonstrate equality as a separate step (possibly a preceding
step):

char *equality[] =
{
"numbers are equal",
"numbers are not equal"
};

Here's another hint: you can turn a number into a string using
sprintf, you can compare two strings for equality using strcmp,
which rather conveniently returns 0 when the two strings are
equal. !!strcmp, of course, returns either 0 or 1.

Here's yet another hint: you are not limited to storing your
original two numbers in strings. You can also store their
difference. If they weren't equal, one will be bigger than
the other. If the second is bigger than the first, the result
of a subtraction will be negative. Detecting a minus sign
in the first byte of a string is trivial.

If an electronic engineer can't get it with all those hints,
there's something wrong with the awards process.

Mike Wahler

unread,
Jan 17, 2005, 2:43:56 AM1/17/05
to
"infobahn" <info...@btinternet.com> wrote in message
news:41EB63B2...@btinternet.com...

> If an electronic engineer can't get it with all those hints,
> there's something wrong with the awards process.

You gave away more than I would have! :-)

The only additional clue I was going to add was
the word "array".

-Mike


Bonj

unread,
Jan 17, 2005, 3:02:08 AM1/17/05
to
Easy - use inline assembly.
Or subtract one from the other and the test the sign bit.


"purifier" <cnbc...@gmail.com> wrote in message

news:19793998f87506ee...@localhost.talkaboutprogramming.com...

Bonj

unread,
Jan 17, 2005, 3:07:13 AM1/17/05
to
People always like to think that the help they're giving is of commercial
value. If they think otherwise, they'll jump on the 'homework' bandwagon.
Happens every time.

"purifier" <cnbc...@gmail.com> wrote in message

news:8a6984c70eddf0d5...@localhost.talkaboutprogramming.com...

Przemek Drochomirecki

unread,
Jan 17, 2005, 3:14:37 AM1/17/05
to

max(a,b) = (abs(a-b)+a+b)>>1;

this hint has of course some obvious limitations :)


przemek drochomirecki

이기운

unread,
Jan 17, 2005, 4:12:24 AM1/17/05
to
Hi~ all

i think that this is the problem about getting sign bit of numbers...
this is very easy... see follow code lines...
you can simplfy multiple lines to a line...


int main(int argc, char *argv[])
{
int a = 2.0;
int b = -23.1;
int lagestNumber = 0;
int signBitCount = (sizeof(int) * 8) - 1;
int signBitMask = 0x1 << signBitCount;
int a_minus_b = a - b;
int b_minus_a = b - a;
int signBitA = 0;
int signBitB = 0;

signBitA = ((unsigned)a_minus_b & signBitMask) >> signBitCount;
signBitB = ((unsigned)b_minus_a & signBitMask) >> signBitCount;

x = (signBitA ^ 0x1) * a + (signBitB ^ 0x1) * b;
printf("lagestNumber = %d\n", lagestNumber);

return 0;
}


"purifier" <cnbc...@gmail.com> wrote in message

news:19793998f87506ee...@localhost.talkaboutprogramming.com...

Peter Nilsson

unread,
Jan 17, 2005, 4:34:46 AM1/17/05
to

"Two's complement" applies to _signed_ integers. The quoted expression
operates on unsigned integers, for which there is only one choice
of representation, namely, pure binary, and for which the behaviour on
overflow is well defined.

--
Peter

CBFalconer

unread,
Jan 17, 2005, 4:50:31 AM1/17/05
to
Bonj wrote:
>
> People always like to think that the help they're giving is of
> commercial value. If they think otherwise, they'll jump on the
> 'homework' bandwagon. Happens every time.

Please don't toppost. As you can see, doing so has lost all
context here. As a matter of fact the 'homework' rejection is
designed to avoid creating a class of useless programmers who have
never learned to do anything themselves. Those that make efforts
but run into difficulties, and demonstrate it by posting their
work, usually get help.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

Peter Nilsson

unread,
Jan 17, 2005, 4:53:53 AM1/17/05
to
À̱â¿î wrote:

Please don't top post in comp.lang.c.

> Hi~ all
>
> i think that this is the problem about getting sign bit of numbers...
> this is very easy... see follow code lines...
> you can simplfy multiple lines to a line...

Missing inclusion of <stdio.h> or prototype for printf.
The behaviour of printf is therefore undefined.

> int main(int argc, char *argv[])
> {
> int a = 2.0;
> int b = -23.1;

This is not _wrong_ wrong, just wrong. ;)

> int lagestNumber = 0;
> int signBitCount = (sizeof(int) * 8) - 1;

A byte may have more than 8 bits. An int may have padding bits.
So, your shift count can be wrong in two ways.

> int signBitMask = 0x1 << signBitCount;

Potential undefined behaviour. Even if the behaviour is defined for
some implementations, it may still be the wrong bit mask.

> int a_minus_b = a - b;
> int b_minus_a = b - a;

Potential overflow for arbitrary a and b.

> int signBitA = 0;
> int signBitB = 0;
>
> signBitA = ((unsigned)a_minus_b & signBitMask) >> signBitCount;
> signBitB = ((unsigned)b_minus_a & signBitMask) >> signBitCount;

An unsigned int need not use the corresponding int sign bit as a
value bit. So your cast may produce zero if a_minus_b is INT_MIN.

> x = (signBitA ^ 0x1) * a + (signBitB ^ 0x1) * b;
> printf("lagestNumber = %d\n", lagestNumber);

lagestNumber is 0 here.

> return 0;
> }

--
Peter

Peter Nilsson

unread,
Jan 17, 2005, 5:07:34 AM1/17/05
to

If unsigned integers looks like two's complement (signed) integers,
it's because two's complement integers look like unsigned integers. ;)

Unsigned types must use 'pure binary', and the behaviour on overflow

Lawrence Kirby

unread,
Jan 17, 2005, 6:51:57 AM1/17/05
to
On Mon, 17 Jan 2005 08:02:08 +0000, Bonj wrote:

> Easy - use inline assembly.

The question was to write a program in C, and C has no inline assembly.

> Or subtract one from the other and the test the sign bit.

Something along those lines may work although making it portable would be
a challenge.

Lawrence

Mike Wahler

unread,
Jan 17, 2005, 12:53:55 PM1/17/05
to
"Bonj" <a...@b.com> wrote in message news:351a1pF...@individual.net...

> People always like to think that the help they're giving is of commercial
> value. If they think otherwise, they'll jump on the 'homework' bandwagon.
> Happens every time.

No, I disagree. Look again at the original question. It's
so obviously a contrived question, and its solution is never
needed in a C program (except for perhaps as a diversionary
'puzzle', but OP didn't label it as such). So I for one,
took it as a general 'problem solving' challenge which might
be a useful learning device (in the context of problem solving,
but imo not for learning C).

Also see Keith T.'s reply, which imo is the best answer to
OP so far.

-Mike


Mike Wahler

unread,
Jan 17, 2005, 12:58:39 PM1/17/05
to

"Peter Nilsson" <ai...@acay.com.au> wrote in message
news:1105955633....@f14g2000cwb.googlegroups.com...
이기운 wrote:

> return 0;
> }

Also, 이기운:

Your errors aside, please don't try to provide solutions
here to folks who've given no evidence of their own efforts
first. This issue may or may not apply to the OP, but here
we like to try to protect ourselves from cheating students
getting a foothold in the ranks of the professionals[*], making
our work unnecessarily more difficult.


[*] by passing a CS course without really learning.

-Mike


--
Peter


purifier

unread,
Jan 17, 2005, 2:34:10 PM1/17/05
to
Enough of those insults... I'm sorry for bothering you guys... I guess this
forum is filled with all time intellectuals... I already explained that I'm
an Electronics Engineer just beginning to learn C... Now why would I lie
about my profession? Come on...there is no reason to... Ok...if it was one
post insulting me then it's ok but it seems that everyone who posts a reply
just insults in some or the other way... It is a pity that you guys are so
rude to beginners like me... Now, how do you want me to prove that i'm not
asking you to do my homework...? Do you want me to sign a bond or what?
The only reason i came here was thinking that this is an open forum... and
thought i could ask for some help... Now, how do i show you my work if I
didn't even understand the problem... Anyway, I won't bother you guys
again... You can talk all the hi fi stuff...

And Admin Sir, Let me finally congratulate you in having such a wonderful
forum... All the above things were my personal opinions because i was hurt
a lot after posting here but your board is definitely helpful for many
experienced programmers to interact... Keep it up Sir...

purifier

Mike Wahler

unread,
Jan 17, 2005, 3:25:01 PM1/17/05
to

"purifier" <cnbc...@gmail.com> wrote in message
news:5c7ae7523d10f035...@localhost.talkaboutprogramming.com...

> Enough of those insults... I'm sorry for bothering you guys... I guess
this
> forum is filled with all time intellectuals... I already explained that
I'm
> an Electronics Engineer just beginning to learn C... Now why would I lie
> about my profession?

A much better question is why would you want to avoid
using a language feature specifically designed to do
what you asked about (comparing values). It also has
a name which lends to code readability (which is important):
'if'.


> Come on...there is no reason to... Ok...if it was one
> post insulting me then it's ok but it seems that everyone who posts a
reply
> just insults in some or the other way... It is a pity that you guys are so
> rude to beginners like me... Now, how do you want me to prove that i'm not
> asking you to do my homework...?

No need to prove that. But please prove that what you're asking
has any practical use in a C program.

> Do you want me to sign a bond or what?
> The only reason i came here was thinking that this is an open forum... and
> thought i could ask for some help... Now, how do i show you my work if I
> didn't even understand the problem...


What you seem to be missing is that their is NO problem.
You want to compare two values, use 'if'.

>Anyway, I won't bother you guys
> again... You can talk all the hi fi stuff...

OK, bye then.

>
> And Admin Sir, Let me finally congratulate you in having such a wonderful
> forum...

This is a public, unmoderated newsgroup. There is no 'admin'.

>All the above things were my personal opinions because i was hurt
> a lot after posting here

IMO you need to develop a thicker skin.

>but your board is definitely helpful for many
> experienced programmers to interact...

It's also been proven to be very helpful to beginners.
But it's not a 'gimme some code' or 'gimme the answer'
forum. We *help* people with what *they* are doing,
we don't simply do it *for* them. I (and others) did
give you some useful hints.


If you really want to figure out the answer to the proposed
(imo ridiculous) question, study some C books, and *give it
a try*. Then I'm sure you'll be pleased with the help you
get.

-Mike


Default User

unread,
Jan 17, 2005, 4:16:50 PM1/17/05
to
purifier wrote:

> And Admin Sir, Let me finally congratulate you in having such a
wonderful
> forum... All the above things were my personal opinions because i was
hurt
> a lot after posting here but your board is definitely helpful for
many
> experienced programmers to interact... Keep it up Sir...


Someone needs a Usenet 101 primer. There's no Admin. There's no
moderator. There's no board. There's no "here" here. There's just a
bunch of heres here and there, connected up into a loose confederation.
And we like it that way.

I see that you post from talkaboutprogramming.com, that's fooled you
into thinking it's a web forum with a small community of participants.
In fact, that's just a portal into a far-flung distributed network
encompassing thousands of servers around the world.

Very few, if any other posters are coming in through your service. Most
ISPs have their own news servers (although some do not). Another
popular way to access usenet is through Google, as I am doing until
such time as they fix our newsfeed.

Brian

Mike Wahler

unread,
Jan 17, 2005, 4:20:31 PM1/17/05
to
"Default User" <defaul...@yahoo.com> wrote in message
news:1105996610.3...@z14g2000cwz.googlegroups.com...

> ISPs have their own news servers (although some do not).


> Another
> popular way to access usenet is through Google, as I am doing until
> such time as they fix our newsfeed.

My condolences. :-)

-Mike


Default User

unread,
Jan 17, 2005, 5:35:16 PM1/17/05
to


It's certainly made me more sympathetic towards those struggling with
using grouple. They sure made a lot of bad decisions. It's hard to
believe that the developers working on the interface could have
actually used usenet much at all.

There's a guy who developed a web-based news service that works much
better than google's. http://www.recgroups.com/?force=1#

It's not perfect, but sure is a lot better interface than google.
>

Brian

Mike Wahler

unread,
Jan 17, 2005, 5:46:51 PM1/17/05
to

"Default User" <defaul...@yahoo.com> wrote in message
news:1106001316....@z14g2000cwz.googlegroups.com...

> Mike Wahler wrote:
> > "Default User" <defaul...@yahoo.com> wrote in message
> > news:1105996610.3...@z14g2000cwz.googlegroups.com...
> > > ISPs have their own news servers (although some do not).
> >
> >
> > > Another
> > > popular way to access usenet is through Google, as I am doing until
> > > such time as they fix our newsfeed.
> >
> > My condolences. :-)
>
>
> It's certainly made me more sympathetic towards those struggling with
> using grouple. They sure made a lot of bad decisions. It's hard to
> believe that the developers working on the interface could have
> actually used usenet much at all.

They probably didn't. They probably take the view of Usenet
as "just another data source". And perhaps they're stripping
whitespace in a misguided attempt to conserve bandwitdth.
But this is just speculation of course.

-Mike


>
> There's a guy who developed a web-based news service that works much
> better than google's. http://www.recgroups.com/?force=1#
>
> It's not perfect, but sure is a lot better interface than google.

There are also public news servers that work with 'real'
news clients (but I realize some organizations limit access
to 'unknown' sources in the interest of security).

-Mike


Default User

unread,
Jan 17, 2005, 6:34:24 PM1/17/05
to
Mike Wahler wrote:

> There are also public news servers that work with 'real'
> news clients (but I realize some organizations limit access
> to 'unknown' sources in the interest of security).


That's our case. The firewall won't allow use of non-approved NNTP
servers. I have an account with the German server which I'd be happy to
use all the time, but no.

Google and ones like I mentioned work because they're actually HTTP. If
I knew of a decent news operation with a good web interface that wasn't
too expensive, I would be interested.

Brian

Bonj

unread,
Jan 17, 2005, 7:21:58 PM1/17/05
to
Sorry - I only top-post because of the fact that it avoids excessive
scrolling to read just the newest addition, especially in messages that
contain a lot of code. Just a personal preference, that's all.
I see the point about not answering homework, and I agree. But I am quite
sceptical of the notion that as many people as there are that chastise
homework-posters are actually making a valiant attempt to change the world
by implicitly teaching the youth of today to use a fishing rod rather than
give them a fish.


Bonj

unread,
Jan 17, 2005, 7:26:37 PM1/17/05
to
He didn't actually say what you can and can't use - which more importantly
means that it's a pretty pointless exercise if this isn't specified. But he
didn't say you *can't* use inline assembly. To me, "write a program in C"
means code in a file with a *.c extension, compiled with a C compiler. It
would be possible to demonstrate inline assembly within those parameters -
like I say, nothing else is specified, nothing like "must be *portable, ISO*
C".


"Lawrence Kirby" <lkn...@netactive.co.uk> wrote in message
news:pan.2005.01....@netactive.co.uk...

Mike Wahler

unread,
Jan 17, 2005, 7:27:31 PM1/17/05
to
"Bonj" <a...@b.com> wrote in message news:353359F...@individual.net...

> Sorry - I only top-post because of the fact that it avoids excessive
> scrolling to read just the newest addition, especially in messages that
> contain a lot of code. Just a personal preference, that's all.

I've done it so many times before, I'll let someone
else try to explain the rationale behind not topposting.

> I see the point about not answering homework, and I agree. But I am quite
> sceptical of the notion that as many people as there are that chastise
> homework-posters are actually making a valiant attempt to change the world
> by implicitly teaching the youth of today to use a fishing rod rather than
> give them a fish.

Cheaters who manage to pass CS curricula and get hired
pose a very real danger to businesses, valid professionals,
and yes, sometimes human life.

Refusing to help them cheat is a defensive action (at least for me).

-Mike


Mike Wahler

unread,
Jan 17, 2005, 9:19:58 PM1/17/05
to

"Bonj" <a...@b.com> wrote in message news:3533e0F...@individual.net...

> He didn't actually say what you can and can't use - which more importantly
> means that it's a pretty pointless exercise if this isn't specified. But
he
> didn't say you *can't* use inline assembly. To me, "write a program in C"

In the context of this newsgroup "C" means ISO standard C.

> means code in a file with a *.c extension,

The name or 'extension' (if any) of a file has nothing
to do with whether it contains C source code. Many
implementations do use (or require) a '.C' 'extension'
to cause compilation as C, but the language has nothing
to say about source file names.

>compiled with a C compiler.

Well yes, a C compiler is needed to tranlate C source code.


> It
> would be possible to demonstrate inline assembly within those parameters -

Not portably. C does define a keyword ('asm') to facilitate
inclusion of assembly code, but the assembly code itself is
(necessarily) not at all standard, not part of the C language.

> like I say, nothing else is specified, nothing like "must be *portable,
ISO*
> C".

Those are indeed implied when talking about "C" in this
newsgroup. If your coursework includes things outside
standard C, this is not the place to discuss them.

BTW please do not top-post in comp.lang.c

-Mike


Jack Klein

unread,
Jan 17, 2005, 11:10:13 PM1/17/05
to
On Tue, 18 Jan 2005 02:19:58 GMT, "Mike Wahler"
<mkwa...@mkwahler.net> wrote in comp.lang.c:

>
> "Bonj" <a...@b.com> wrote in message news:3533e0F...@individual.net...
> > He didn't actually say what you can and can't use - which more importantly
> > means that it's a pretty pointless exercise if this isn't specified. But
> he
> > didn't say you *can't* use inline assembly. To me, "write a program in C"
>
> In the context of this newsgroup "C" means ISO standard C.
>
> > means code in a file with a *.c extension,
>
> The name or 'extension' (if any) of a file has nothing
> to do with whether it contains C source code. Many
> implementations do use (or require) a '.C' 'extension'
> to cause compilation as C, but the language has nothing
> to say about source file names.
>
> >compiled with a C compiler.
>
> Well yes, a C compiler is needed to tranlate C source code.
>
>
> > It
> > would be possible to demonstrate inline assembly within those parameters -
>
> Not portably. C does define a keyword ('asm') to facilitate
> inclusion of assembly code, but the assembly code itself is
> (necessarily) not at all standard, not part of the C language.

Sorry, Mike, you're flat-out wrong on this one. There is no 'asm'
keyword in any version of the C standard. It was an extension prior
to ANSI 89/ISO 90, but was not included in those or any later C
standards.

It is a keyword in C++, but of course that's OT here.

> > like I say, nothing else is specified, nothing like "must be *portable,
> ISO*
> > C".
>
> Those are indeed implied when talking about "C" in this
> newsgroup. If your coursework includes things outside
> standard C, this is not the place to discuss them.
>
> BTW please do not top-post in comp.lang.c
>
> -Mike

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html

CBFalconer

unread,
Jan 17, 2005, 11:55:03 PM1/17/05
to
Mike Wahler wrote:
> "Bonj" <a...@b.com> wrote

>
>> Sorry - I only top-post because of the fact that it avoids excessive
>> scrolling to read just the newest addition, especially in messages
>> that contain a lot of code. Just a personal preference, that's all.
>
> I've done it so many times before, I'll let someone
> else try to explain the rationale behind not topposting.

I'll just let the links in my sig do the explaining.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html


Mike Wahler

unread,
Jan 18, 2005, 1:48:28 AM1/18/05
to
"Jack Klein" <jack...@spamcop.net> wrote in message
news:6t2pu0h17cld6nl82...@4ax.com...

> On Tue, 18 Jan 2005 02:19:58 GMT, "Mike Wahler"
> <mkwa...@mkwahler.net> wrote in comp.lang.c:
> > > It
> > > would be possible to demonstrate inline assembly within those
parameters -
> >
> > Not portably. C does define a keyword ('asm') to facilitate
> > inclusion of assembly code, but the assembly code itself is
> > (necessarily) not at all standard, not part of the C language.
>
> Sorry, Mike, you're flat-out wrong on this one. There is no 'asm'
> keyword in any version of the C standard. It was an extension prior
> to ANSI 89/ISO 90, but was not included in those or any later C
> standards.
>
> It is a keyword in C++, but of course that's OT here.

I did find 'asm' in ISO 9899, but failed to note it was in
section J.5, "Common extensions", and that the entire 'J'
section is informative, not normative. Sloppy, sloppy detective
work... :-)

Thanks for the correction.


-Mike


Keith Thompson

unread,
Jan 18, 2005, 1:56:23 AM1/18/05
to
"Bonj" <a...@b.com> writes:
> Sorry - I only top-post because of the fact that it avoids excessive
> scrolling to read just the newest addition, especially in messages that
> contain a lot of code. Just a personal preference, that's all.
[snip]

A number of people have explained the rationale behind our reasons for
not top-posting. Several links have been posted in this thread.
Please read them. (Basically, it makes it easier to read each article
from top to bottom. If there's too much quoted text, the solution is
to trim it, not to try to hide it at the bottom.)

If you don't believe that, consider the fact that most of us here, and
100% of the regulars, always bottom-post. The only thing worse than
either top-posting or bottom-posting is a mixture of the two. "When
in Rome ...".

And if you don't take that seriously, you need to be aware that people
are going to complain every time you top-post. It's not going to be
the same people every time, and asking us not to complain isn't going
to work. That's not in any way meant as a threat, it's just a fact
about the dynamics of this newsgroup.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Kishore

unread,
Jan 18, 2005, 4:45:11 AM1/18/05
to
#include <stdio.h>
main () {
int a, b ;
printf ("Enter a and b\n") ;
scanf ("%d%d", &a, &b) ;
((a > b) && printf ("a is bigger\n")) || ((b > a) && printf ("b is
Biger\n")) || ((a == b) && printf ("Both r equal\n")) ;
}

This is the program with out using if and ternary operator.if any
mistake is there pls let me know that one.

regards
Kishore Kumar .M.V

Chris Dollin

unread,
Jan 18, 2005, 5:45:17 AM1/18/05
to
purifier wrote:

> The problem is to write a program in 'C' to find the greatest of 2 given
> numbers... Easy? huh
> here's the catch
> do not use 'if' or any conditional statements
> if u want it to be a little more tougher you can use the if but this time
> no relational operators or any of the predefined functions....
>
> Can someone please help me solve the problem....

<fx:whistling/>

max = (a > b ? a : b);

no ifs, no conditional statements.

--
Chris "letter, not spirit" Dollin

Lawrence Kirby

unread,
Jan 18, 2005, 6:10:07 AM1/18/05
to
On Mon, 17 Jan 2005 20:25:01 +0000, Mike Wahler wrote:

>
> "purifier" <cnbc...@gmail.com> wrote in message
> news:5c7ae7523d10f035...@localhost.talkaboutprogramming.com...
>> Enough of those insults... I'm sorry for bothering you guys... I guess
> this
>> forum is filled with all time intellectuals... I already explained that
> I'm
>> an Electronics Engineer just beginning to learn C... Now why would I lie
>> about my profession?
>
> A much better question is why would you want to avoid
> using a language feature specifically designed to do
> what you asked about (comparing values). It also has
> a name which lends to code readability (which is important):
> 'if'.

One answer to that can be fun and recreational programming. And by
exploring the language with unusual contraints you can sometimes learn
something new and surprising about the language and what it can do.

Lawrence

Lawrence Kirby

unread,
Jan 18, 2005, 6:14:52 AM1/18/05
to
On Tue, 18 Jan 2005 00:21:58 +0000, Bonj wrote:

> Sorry - I only top-post because of the fact that it avoids excessive
> scrolling to read just the newest addition, especially in messages that
> contain a lot of code. Just a personal preference, that's all.

...

If there is excessive scrolling then you haven't trimmed the article you
are replying to properly. That is important (perhaps the more serious
issue) whether you top or bottom post. And it is *not* the common case
that articles you are replying to contain lots of code.

Lawrence

pete

unread,
Jan 18, 2005, 7:39:14 AM1/18/05
to

That is the most conditional that a statement can be.
It uses the conditional operator.

--
pete

Chris Dollin

unread,
Jan 18, 2005, 8:27:42 AM1/18/05
to
pete wrote:

Which is an *expression*, not a statement. The *statement*
is unconditionally an assignment.

Of course

max = (a > b) * a + (a <= b) * b;

avoids even that nitpick.

--
Chris "electric hedgehog" Dollin

vsk

unread,
Jan 18, 2005, 8:42:59 AM1/18/05
to
Hai All,

int main()
{
int a = 10;
int b = -12;
printf ("Bigger is : %d",find_big(a,b));
}
int find_big(int a, int b)
{
return a>b?a:b;
}

Thanks,
VSK

osmium

unread,
Jan 18, 2005, 8:44:00 AM1/18/05
to
"Chris Dollin" writes:

K&R describe a conditional expression in the text on p. 51. But look at the
BNF in the same book. As soon as you put a semi-colon after it it becomes a
conditional *statement*. And without the semi-colon the compiler will barf.


purifier

unread,
Jan 18, 2005, 9:18:17 AM1/18/05
to
Hi vsk,
but that uses the ternary operator right? That one, if i'm not mistaken is
just another form of if-else...
Please have a look at the solution given by Mr.Kishore and Mr.Chris
Dollin...

I got one idea... why not use the absolute value function..
(|a+b|+|a-b|/2)will give out the greater of the two numbers but only when
both the numbers are positive...

Chris Dollin

unread,
Jan 18, 2005, 10:05:19 AM1/18/05
to
osmium wrote:

> "Chris Dollin" writes:
>
>> pete wrote:
>>
>>> Chris Dollin wrote:
>>>>
>>>> purifier wrote:

[snip]

>>>> <fx:whistling/>
>>>>
>>>> max = (a > b ? a : b);
>>>>
>>>> no ifs, no conditional statements.
>>>
>>> That is the most conditional that a statement can be.
>>> It uses the conditional operator.
>>
>> Which is an *expression*, not a statement. The *statement*
>> is unconditionally an assignment.
>>
>> Of course
>>
>> max = (a > b) * a + (a <= b) * b;
>>
>> avoids even that nitpick.
>
> K&R describe a conditional expression in the text on p. 51. But look at
> the
> BNF in the same book. As soon as you put a semi-colon after it it becomes
> a
> conditional *statement*. And without the semi-colon the compiler will
> barf.

(a) The semi-colon converts the *assignment* into a statement, not the
immediately-preceeding conditional expression. "Conditional statement"
usually refers to an if-then-[else], not to a statement that happens
to embed an expression that happens to use a conditional expression.

(b) consider
int max = a > b ? a : b;

There's no *statement* there at all (since it's a declaration), so
there isn't a *conditional* statement either.

<fx:stillWhistling/>

Kenneth Brody

unread,
Jan 18, 2005, 10:03:50 AM1/18/05
to
purifier wrote:
>
> The problem is to write a program in 'C' to find the greatest of 2 given
> numbers...

By definition, you cannot find the "greatest" of two things.

[... Remainder of homework problem deleted ...]

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:ThisIsA...@gmail.com>

purifier

unread,
Jan 18, 2005, 10:28:49 AM1/18/05
to
>By definition, you cannot find the "greatest" of >two things.

Now, what in the world do you mean by that...

>[... Remainder of homework problem deleted ...]

Now, don't come back to the beginning Mr.Kenneth Brody... I already made
it clear that this one is not a homework problem... If you have any
suggestions, then reply,otherwise, fine...please don't reply... No one is
forcing you to reply over here...

Keith Thompson

unread,
Jan 18, 2005, 10:52:26 AM1/18/05
to
"purifier" <cnbc...@gmail.com> writes:
> but that uses the ternary operator right? That one, if i'm not mistaken is
> just another form of if-else...
[...]

The ternary operator has similar semantics to if-then-else, but it's
not another form of it. For one thing, it's an operator, not a
statement.

The original problem statement said:

do not use 'if' or any conditional statements

If you want to restrict the use of the ternary operator, you need to
say so in the problem definition. It would also be good to define
exactly what you mean by "conditional statements".

If, as you say, this is meant to be a fun little puzzle, we're free to
exploit any possible nitpicking interpretation of the question
(reasonableness doesn't apply since the whole idea is not particularly
reasonable).

Incidentally, I can think of a reasonable reason to want to find the
greater of two numbers without using certain constructs. Conditional
branches, on some systems, can cause performance problems by messing
with pipelining, instruction caches, and other off-topic stuff. If
performance is sufficiently important, it just might be worthwhile to
micro-optimize such an operation. If you can state the restrictions
in portable C terms (even if the motivation for the restrictions is
off-topic), you might have an interesting question.

Chris Dollin

unread,
Jan 18, 2005, 10:58:57 AM1/18/05
to
Kenneth Brody wrote:

> purifier wrote:
>>
>> The problem is to write a program in 'C' to find the greatest of 2 given
>> numbers...
>
> By definition, you cannot find the "greatest" of two things.

That's a pretty useless definition, then. Me, I can find the greatest
of *one* thing. It's the greatest of *no* things that's tricky.

Kenneth Brody

unread,
Jan 18, 2005, 10:48:45 AM1/18/05
to
purifier wrote:
>
> >By definition, you cannot find the "greatest" of >two things.
>
> Now, what in the world do you mean by that...

"Greatest" requires at least three items. For two, you want the "greater".

Randy Howard

unread,
Jan 18, 2005, 11:16:43 AM1/18/05
to
In article <pan.2005.01.18....@netactive.co.uk>,
lkn...@netactive.co.uk says...

Absolutely. I enjoy reading these threads, because when the "gang-
tackling by geeks" part of it dies out, invariably someone posts a
novel solution to a problem that I had not thought of before.

--
Randy Howard (2reply remove FOOBAR)
"For some reason most people seem to be born without the part
of the brain that understands pointers." -- Joel Spolsky

purifier

unread,
Jan 18, 2005, 11:28:35 AM1/18/05
to
Mr.Kenneth Brody... Why being so formal... When I was able to convey the
meaning to people...where is the need for you to point out that
grammatical mistake? Anyway...cool....

infobahn

unread,
Jan 18, 2005, 11:39:40 AM1/18/05
to
purifier wrote:
>
> >By definition, you cannot find the "greatest" of two things.
>
> Now, what in the world do you mean by that...

He means that "greatest" traditionally refers to the - um - greatest
of a group, rather than just two. For two, the word "greater" is used.

Richard Bos

unread,
Jan 18, 2005, 11:40:57 AM1/18/05
to
Keith Thompson <ks...@mib.org> wrote:

> Incidentally, I can think of a reasonable reason to want to find the
> greater of two numbers without using certain constructs. Conditional
> branches, on some systems, can cause performance problems by messing
> with pipelining, instruction caches, and other off-topic stuff. If
> performance is sufficiently important, it just might be worthwhile to
> micro-optimize such an operation.

Whatever happened to Jackson's Laws? If the compiler cannot perform such
optimisations, they most probably do not work anyway.

Richard

Mike Wahler

unread,
Jan 18, 2005, 11:58:17 AM1/18/05
to
"Chris Dollin" <ke...@hpl.hp.com> wrote in message
news:csjbo1$cus$1...@malatesta.hpl.hp.com...

> Kenneth Brody wrote:
>
> > purifier wrote:
> >>
> >> The problem is to write a program in 'C' to find the greatest of 2
given
> >> numbers...
> >
> > By definition, you cannot find the "greatest" of two things.
>
> That's a pretty useless definition, then. Me, I can find the greatest
> of *one* thing.

I certainly hope so. My wife tells me I'm her
favorite husband. :-)

-Mike


Ben Pfaff

unread,
Jan 18, 2005, 12:10:20 PM1/18/05
to
r...@hoekstra-uitgeverij.nl (Richard Bos) writes:

> Whatever happened to Jackson's Laws? If the compiler cannot perform such
> optimisations, they most probably do not work anyway.

Google's top hit for Jackson's Law is "Loss of mental functions
due to disease retraces in reverse order its evolutionary
development." If that's not what you mean, perhaps you should
elaborate. Actually, even if that's what you mean I'd appreciate
elaboration.
--
"I've been on the wagon now for more than a decade. Not a single goto
in all that time. I just don't need them any more. I don't even use
break or continue now, except on social occasions of course. And I
don't get carried away." --Richard Heathfield

Michael Wojcik

unread,
Jan 18, 2005, 12:08:03 PM1/18/05
to

In article <csj2se$8ui$1...@malatesta.hpl.hp.com>, Chris Dollin <ke...@hpl.hp.com> writes:
>
> max = (a > b) * a + (a <= b) * b;

If we restrict a and b to positive integers, we can get rid of those
relational-operator crutches, using integer division and the !!-trick:

max = ((!!(a/b) * a) + (!!(b/a) * b)) / (!!(a/b) + !!(b/a));

(The final division handles the case where a == b; then the sum is
a+b rather than a+0 or 0+b, so we have to divide by two in that
case. The denominator evaluates to 2 if a == b, and 1 otherwise.)

We could extend this to handle zero by adding 1 to a and b first,
then subtracting 1 from the answer:

max = ((!!((a+1)/(b+1)) * (a+1)) + (!!((b+1)/(a+1)) * (b+1))) /
(!!((a+1)/(b+1)) + !!((b+1)/(a+1)))
- 1;

Handling cases where a and b have different signs looks a bit more
complicated, so I'm not going to bother.

--
Michael Wojcik michael...@microfocus.com

Unlikely predition o' the day:
Eventually, every programmer will have to write a Java or distributed
object program.
-- Orfali and Harkey, _Client / Server Programming with Java and CORBA_

Default User

unread,
Jan 18, 2005, 2:27:31 PM1/18/05
to

You really need to start quoting properly. If that web site you use to
post doesn't allow it, don't use it. I'd suggest a real news service if
possible, groups.google as a last resort (what I'm using). Your ISP may
provide a newsfeed, if not the server at http://news.individual.net is
free with registration.

Brian

Keith Thompson

unread,
Jan 18, 2005, 3:02:43 PM1/18/05
to

Agreed. Learning to program in C involves learning to do the hard
stuff as well as the easy stuff, understanding the more obscure and
difficult features of the language. The trick for an educator is
figuring out how to assign problems that force the student to do the
hard stuff. One way to do this is to assign a problem that can be
solved easily, but forcing the student to solve it with one hand tied
behind his back (by restricting the features that can be used). The
result is something that's entirely unrealistic in real-world terms,
but a more realistic problem that actually needs the difficult
features might be beyond the students' ability.

The risk is that the students might assume that there's some virtue in
doing things the hard way when it's not really necessary.

CBFalconer

unread,
Jan 18, 2005, 6:09:39 PM1/18/05
to
purifier wrote:
>
>> By definition, you cannot find the "greatest" of two things.
>
> Now, what in the world do you mean by that...

By definition, Ali is the greatest. You probably meant the greater.

>
> >[... Remainder of homework problem deleted ...]
>
> Now, don't come back to the beginning Mr.Kenneth Brody... I
> already made it clear that this one is not a homework problem...
> If you have any suggestions, then reply,otherwise, fine...please
> don't reply... No one is forcing you to reply over here...

Since all potential homework problems are immeditately rejected or
argued over for a week or so, the mechanism ensures that any
homework answers arrive too late for submission, and thus do not
exacerbate the flood of incompetent programmers.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


Richard Bos

unread,
Jan 19, 2005, 2:23:27 AM1/19/05
to
Ben Pfaff <b...@cs.stanford.edu> wrote:

> r...@hoekstra-uitgeverij.nl (Richard Bos) writes:
>
> > Whatever happened to Jackson's Laws? If the compiler cannot perform such
> > optimisations, they most probably do not work anyway.
>
> Google's top hit for Jackson's Law is "Loss of mental functions
> due to disease retraces in reverse order its evolutionary
> development." If that's not what you mean, perhaps you should
> elaborate. Actually, even if that's what you mean I'd appreciate
> elaboration.

Jackson's Laws of Optimisation:

1. Don't do it.
2. (For experts only) Don't do it yet.

Someone around here had them in his .sig, at one time.

Richard

Peter Nilsson

unread,
Jan 19, 2005, 5:08:41 AM1/19/05
to
Michael Wojcik wrote:
> If we restrict a and b to positive integers, ...
>
> <snip>

>
> max = ((!!((a+1)/(b+1)) * (a+1)) + (!!((b+1)/(a+1)) * (b+1))) /
> (!!((a+1)/(b+1)) + !!((b+1)/(a+1)))
> - 1;

If a and b are unsigned int, and either one is UINT_MAX, you have
division by zero.

If a and b are int, and either one is INT_MAX, you have overflow.
--
Peter

Chris Dollin

unread,
Jan 19, 2005, 7:03:24 AM1/19/05
to
Kenneth Brody wrote:

> purifier wrote:
>>
>> >By definition, you cannot find the "greatest" of >two things.
>>
>> Now, what in the world do you mean by that...
>
> "Greatest" requires at least three items. For two, you want the
> "greater".

You might accept that as a grammatical constraint; I don't.

As side-curiosity, would you accept, using "your" definition

"find the greatest of a, b, and c"
where a = 42, b = 17, c = 42
?

pete

unread,
Jan 19, 2005, 8:14:05 AM1/19/05
to

I would.
I learned English the same way as purifer did.

--
pete

Chris Dollin

unread,
Jan 19, 2005, 8:51:56 AM1/19/05
to
pete wrote:

There's only two items in this example.

I *said* it was a side-curiosity.

pete

unread,
Jan 19, 2005, 9:06:24 AM1/19/05
to

I counted a, b and c as three items.

> I *said* it was a side-curiosity.

--
pete

Chris Dollin

unread,
Jan 19, 2005, 9:35:41 AM1/19/05
to
pete wrote:

Those are the *names* of the items. The items are 42 and 17. Otherwise
the answer would likely be "c" ...

>> I *said* it was a side-curiosity.

Ditto.

Richard Bos

unread,
Jan 19, 2005, 10:57:20 AM1/19/05
to
Kenneth Brody <kenb...@spamcop.net> wrote:

> purifier wrote:
> >
> > >By definition, you cannot find the "greatest" of >two things.
> >
> > Now, what in the world do you mean by that...
>
> "Greatest" requires at least three items. For two, you want the "greater".

Several dictionaries disagree with you. The OED, for example, calls
"greatest" the superlative tense of "great"; and under "superlative" it
says that superlatives are used for the highest in degree of a _number_
of choices. Not "number greater than two"; "number".

Richard

Michael Wojcik

unread,
Jan 19, 2005, 11:10:58 AM1/19/05
to

In article <1106129321.3...@c13g2000cwb.googlegroups.com>, "Peter Nilsson" <ai...@acay.com.au> writes:
> Michael Wojcik wrote:
> > If we restrict a and b to positive integers, ...
> >
> > max = ((!!((a+1)/(b+1)) * (a+1)) + (!!((b+1)/(a+1)) * (b+1))) /
> > (!!((a+1)/(b+1)) + !!((b+1)/(a+1)))
> > - 1;
>
> If a and b are unsigned int, and either one is UINT_MAX, you have
> division by zero.
>
> If a and b are int, and either one is INT_MAX, you have overflow.

Yes, in one draft of that post I had a qualification about remaining
below the maximum value of the type of a and b, but apparently I
removed it during editing. It's so obvious I hardly think it's worth
pointing out anyway; we could make the same criticism of most code
snippets posted to c.l.c. Clearly the expression above fails to work
for values *greater* than the maximum of the type, since we can't
even put them into a and b; should I have mentioned that?

--
Michael Wojcik michael...@microfocus.com

Even though there may be some misguided critics of what we're trying
to do, I think we're on the wrong path. -- Reagan

Michael Wojcik

unread,
Jan 19, 2005, 11:19:03 AM1/19/05
to

In article <csliac$eig$1...@malatesta.hpl.hp.com>, Chris Dollin <ke...@hpl.hp.com> writes:
> Kenneth Brody wrote:
> > purifier wrote:
> >>
> >> >By definition, you cannot find the "greatest" of >two things.
> >>
> >> Now, what in the world do you mean by that...
> >
> > "Greatest" requires at least three items. For two, you want the
> > "greater".
>
> You might accept that as a grammatical constraint; I don't.

It's a question of usage, not grammar. No matter of grammar is under
debate. English grammar tells us that "greatest" is the superlative
form of the adjective "great", and that "greater" is the comparative
form. Whether the superlative is properly used for a set of fewer
than three items is a matter of usage.

Preferring the comparative when only two items are being compared is
certainly longstanding and widespread among those who advocate
specific usages in English.

--
Michael Wojcik michael...@microfocus.com

Thus, the black lie, issuing from his base throat, becomes a boomerang to
his hand, and he is hoist by his own petard, and finds himself a marked man.
-- attributed to a "small-town newspaper editor in Wisconsin"

jmac...@gmail.com

unread,
Jan 19, 2005, 8:09:56 PM1/19/05
to
There are tons of asshole on programmng forum so beware.
They forget what it was like to be new I guess.

l00pyl

Chris Dollin

unread,
Jan 20, 2005, 5:20:03 AM1/20/05
to
Michael Wojcik wrote:


> In article <csliac$eig$1...@malatesta.hpl.hp.com>, Chris Dollin
> <ke...@hpl.hp.com> writes:
>> Kenneth Brody wrote:
>> > purifier wrote:
>> >>
>> >> >By definition, you cannot find the "greatest" of >two things.
>> >>
>> >> Now, what in the world do you mean by that...
>> >
>> > "Greatest" requires at least three items. For two, you want the
>> > "greater".
>>
>> You might accept that as a grammatical constraint; I don't.
>
> It's a question of usage, not grammar. No matter of grammar is under
> debate. English grammar tells us that "greatest" is the superlative
> form of the adjective "great", and that "greater" is the comparative
> form. Whether the superlative is properly used for a set of fewer
> than three items is a matter of usage.

Well, I'm not convinced, but that's partly because my notion of
grammar for natural language is as a description of usage, so I'm
not making the distinction in the same way you are.

> Preferring the comparative when only two items are being compared is
> certainly longstanding and widespread among those who advocate
> specific usages in English.

I think my position here is that I'd use "greatest" and "greater" without
organised preference, for any non-empty collections of items, but of
course I might be empirically wrong and in any case my usage has been
heavily influenced by mathematics.

*I* am happy to say "all my helicopters are heavily armed" and "our
biggest cat is on the bed". (But I might not be so happy to say that
to a policeman.)

Richard Bos

unread,
Jan 20, 2005, 7:36:54 AM1/20/05
to
mwo...@newsguy.com (Michael Wojcik) wrote:

> Preferring the comparative when only two items are being compared is
> certainly longstanding and widespread among those who advocate
> specific usages in English.

Preferring it, yes. Demanding it of others, no. "The greater of the two"
is correct. "The greatest of the two" is not wrong.

Richard

Lawrence Kirby

unread,
Jan 20, 2005, 10:55:40 AM1/20/05
to
On Wed, 19 Jan 2005 14:35:41 +0000, Chris Dollin wrote:

...

>> I counted a, b and c as three items.
>
> Those are the *names* of the items.

Correct, the items themselves are the three objects/variables these
represent.

> The items are 42 and 17.

Those are properties of the items. It just happens that two items share
the same property. That does not make them the same item. I have 3 coins
in my hand which I will label x, y and z. The fact that x and z are of the
same denomination does not suddenly mean that I only have 2 coins in my
hand.

> Otherwise
> the answer would likely be "c" ...

When you use a comparative or superlative form you are comparing a common
property, usually as defined by the base adjective. The assumption here
was the property in question "great-ness" was the value, but that may be a
wrong assumption. If so the fault is in the question for not being clear.

Lawrence

CBFalconer

unread,
Jan 20, 2005, 11:19:51 AM1/20/05
to

Go ahead. You have my permission (if not blessing) to cavalierly
use 'greatest' as you wish. Do not misconstrue this as a license
to use the broken google usenet interface, nor to top-post, nor to
fail to snip, nor to 'edit' quoted material, nor to use
'doodspeak', nor to attach binaries. :-) I am sure you have been
eagerly awaiting this permission.

Michael Wojcik

unread,
Jan 20, 2005, 2:11:37 PM1/20/05
to

In article <cso0kj$ksd$1...@malatesta.hpl.hp.com>, Chris Dollin <ke...@hpl.hp.com> writes:
> Michael Wojcik wrote:
> > In article <csliac$eig$1...@malatesta.hpl.hp.com>, Chris Dollin
> > <ke...@hpl.hp.com> writes:
> >>
> >> You might accept that as a grammatical constraint; I don't.
> >
> > It's a question of usage, not grammar. No matter of grammar is under
> > debate. English grammar tells us that "greatest" is the superlative
> > form of the adjective "great", and that "greater" is the comparative
> > form. Whether the superlative is properly used for a set of fewer
> > than three items is a matter of usage.
>
> Well, I'm not convinced, but that's partly because my notion of
> grammar for natural language is as a description of usage,

Exactly. English grammar is descriptive (specifically, of syntax),
not proscriptive.

> so I'm not making the distinction in the same way you are.

Clearly, but that doesn't follow from grammar being a description
of usage. If grammar describes usage, then an error of grammar
can only be an error of description, not an "error" in the actual
use of language in the statement in question.

> I think my position here is that I'd use "greatest" and "greater" without
> organised preference, for any non-empty collections of items,

I wouldn't try to stop you. (I actually do possess a secret doomsday
weapon with which I could enforce my language preferences on everyone,
but I don't wield it for trifles.) I prefer the comparative when
dealing with two items, but the use of the superlative in that context
is pretty widespread. The comparative for more than two ("he was the
wittier of the three"?) is, I think, less common, but understanding
probably won't be dramatically impaired by it.

> but of course I might be empirically wrong

In a matter of usage? I'm not sure empiricism applies.

> and in any case my usage has been heavily influenced by mathematics.

Where I agree that distinguishing the dual case would be a pointless
inconvenience.

> *I* am happy to say "all my helicopters are heavily armed" and "our
> biggest cat is on the bed". (But I might not be so happy to say that
> to a policeman.)

Those cat police are a caution, aren't they?

--
Michael Wojcik michael...@microfocus.com

They had forgathered enough of course in all the various times; they had
again and again, since that first night at the theatre, been face to face
over their question; but they had never been so alone together as they were
actually alone - their talk hadn't yet been so supremely for themselves.
-- Henry James

Mike Wahler

unread,
Jan 20, 2005, 3:10:41 PM1/20/05
to
"Richard Bos" <r...@hoekstra-uitgeverij.nl> wrote in message
news:41efa5ac....@news.individual.net...

The greatest of 2 is 2.

Now someone please write a C expression which
proves this. :-)

-Mike


Albert van der Horst

unread,
Jan 20, 2005, 2:56:03 PM1/20/05
to
In article <8a6984c70eddf0d5...@localhost.talkaboutprogramming.com>,
purifier <cnbc...@gmail.com> wrote:
>It's a real sad thing to know, Sir... I didn't expect that my post would
>make you think that it was my homework... I'm an Electronics Engineer, but
>i'm interested a lot in programming... One of my friends asked me this
>question in a mail. I just pasted that mail here... For your information i
>even said "Can you please help me solve the problem" Why would I say huh
>and all kinds of stuff and then ask people to solve the problem? I could
>have directly given the problem...
>Anyway, Sorry if i mislead you guys... Thank you for the replies.. Atleast
>if possible, please give me some ideas...

The following is not correct. But there is an idea inside.
Though it is not correct, it works.

x = -(a<b);
y = -!x;
max = (b&x)|(y&a);

(You may want to take a course DEC Alpha assembler programming.)

>Thank You
>

--

Groetjes Albert
--
Albert van der Horst,Oranjestr 8,3511 RA UTRECHT,THE NETHERLANDS
One man-hour to invent,
One man-week to implement,
One lawyer-year to patent.

Ben Pfaff

unread,
Jan 20, 2005, 3:58:58 PM1/20/05
to
r...@hoekstra-uitgeverij.nl (Richard Bos) writes:

I think the former example is the best usage.
--
<g,d&r>

Mike Wahler

unread,
Jan 20, 2005, 4:58:47 PM1/20/05
to

"Albert van der Horst" <alb...@spenarnc.xs4all.nl> wrote in message
news:iamsp...@spenarnc.xs4all.nl...

> In article
<8a6984c70eddf0d5...@localhost.talkaboutprogramming.com>,
> purifier <cnbc...@gmail.com> wrote:
> >It's a real sad thing to know, Sir... I didn't expect that my post would
> >make you think that it was my homework... I'm an Electronics Engineer,
but
> >i'm interested a lot in programming... One of my friends asked me this
> >question in a mail. I just pasted that mail here... For your information
i
> >even said "Can you please help me solve the problem" Why would I say huh
> >and all kinds of stuff and then ask people to solve the problem? I could
> >have directly given the problem...
> >Anyway, Sorry if i mislead you guys... Thank you for the replies..
Atleast
> >if possible, please give me some ideas...
>
> The following is not correct. But there is an idea inside.
> Though it is not correct, it works.
>
> x = -(a<b);
> y = -!x;
> max = (b&x)|(y&a);
>
> (You may want to take a course DEC Alpha assembler programming.)

Since I think enough time has passed :-), and I haven't
seen the 'array method' posted yet, here it is (if the
inputs are equal, returns the first.):

int greater(int n1, int n2)
{
int a[2] = {n1, n2};
return a[n1 < n2];
}

-Mike


Albert van der Horst

unread,
Jan 20, 2005, 4:26:56 PM1/20/05
to
In article <lnekgi9...@nuthaus.mib.org>,
Keith Thompson <ks...@mib.org> wrote:
<SNIP>
>
>Incidentally, I can think of a reasonable reason to want to find the
>greater of two numbers without using certain constructs. Conditional
>branches, on some systems, can cause performance problems by messing
>with pipelining, instruction caches, and other off-topic stuff. If
>performance is sufficiently important, it just might be worthwhile to
>micro-optimize such an operation. If you can state the restrictions
>in portable C terms (even if the motivation for the restrictions is
>off-topic), you might have an interesting question.

Like this?
------------
int test(int a, int b)
{
return a<b? b: a;
}
int test2(int a, int b)
{
int c;

if (a<b)
c=b;
else
c=a;

return c;
}
-----------------------
This is what the gnu c-compiler delivers on DEC alpha
(-O3). There is no jump in sight. The code is the same
for both functions.

For the uninitiated: I have commented the code.
>
.file 1 "aap.c"
.version "01.01"
.set noat
gcc2_compiled.:
__gnu_compiled_c:
.text
.align 3
.globl test
.ent test
test:
$test..ng:
.frame $30,0,$26,0
.prologue 0
cmple $17,$16,$1 r1 = (a<=b);
bis $16,$16,$0 r0 = b; (literally r0 = b|b; )
cmoveq $1,$17,$0 if (r1) r0 = a;
ret $31,($26),1
.end test
.align 3
.globl test2
.ent test2
test2:
$test2..ng:
.frame $30,0,$26,0
.prologue 0
cmple $16,$17,$1
bis $17,$17,$0
cmoveq $1,$16,$0
ret $31,($26),1
.end test2
.ident "GCC: (GNU) egcs-2.90.27 980315 (egcs-1.0.2 release)"
-------------

Or is this what you mean by off topic?



>--
>Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
>San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
>We must do something. This is something. Therefore, we must do this.

--

Keith Thompson

unread,
Jan 21, 2005, 3:17:02 AM1/21/05
to
Albert van der Horst <alb...@spenarnc.xs4all.nl> writes:
> In article <lnekgi9...@nuthaus.mib.org>,
> Keith Thompson <ks...@mib.org> wrote:
> <SNIP>
>>
>>Incidentally, I can think of a reasonable reason to want to find the
>>greater of two numbers without using certain constructs. Conditional
>>branches, on some systems, can cause performance problems by messing
>>with pipelining, instruction caches, and other off-topic stuff. If
>>performance is sufficiently important, it just might be worthwhile to
>>micro-optimize such an operation. If you can state the restrictions
>>in portable C terms (even if the motivation for the restrictions is
>>off-topic), you might have an interesting question.
>
> Like this?
[snip example showing generated code with no jumps]

Good point; most compilers do a pretty good job of optimizing jumps
away if it makes sense to do so for a given processor (and, just as
important, not doing so if it doesn't make sense).

I'll amend my above statement to say that this kind of
micro-optimization might make sense given the above circumstances *if*
you don't have a compiler that can do the optimization for you. (That
may not be an issue these days.)

Chris Dollin

unread,
Jan 21, 2005, 4:49:54 AM1/21/05
to
Michael Wojcik wrote:

>
> In article <cso0kj$ksd$1...@malatesta.hpl.hp.com>, Chris Dollin
> <ke...@hpl.hp.com> writes:

>> I think my position here is that I'd use "greatest" and "greater" without
>> organised preference, for any non-empty collections of items,
>
> I wouldn't try to stop you. (I actually do possess a secret doomsday
> weapon with which I could enforce my language preferences on everyone,
> but I don't wield it for trifles.) I prefer the comparative when
> dealing with two items, but the use of the superlative in that context
> is pretty widespread. The comparative for more than two ("he was the
> wittier of the three"?) is, I think, less common, but understanding
> probably won't be dramatically impaired by it.
>
>> but of course I might be empirically wrong
>
> In a matter of usage? I'm not sure empiricism applies.

Sorry, I mean that I might be empirically wrong about my usage patterns.
(Self-observation is tricky, even more subject to selection effects than
observation of others.)

>> *I* am happy to say "all my helicopters are heavily armed" and "our
>> biggest cat is on the bed". (But I might not be so happy to say that
>> to a policeman.)
>
> Those cat police are a caution, aren't they?

There appearance can be arresting, also.

Mabden

unread,
Jan 23, 2005, 7:35:04 AM1/23/05
to
"purifier" <cnbc...@gmail.com> wrote in message
news:5c7ae7523d10f035...@localhost.talkaboutprogramming.com...
> Enough of those insults... I'm sorry for bothering you guys... I guess
this
> forum is filled with all time intellectuals... I already explained
that I'm
> an Electronics Engineer just beginning to learn C... Now why would I
lie
> about my profession? Come on...there is no reason to... Ok...if it was
one
> post insulting me then it's ok but it seems that everyone who posts a
reply
> just insults in some or the other way... It is a pity that you guys
are so
> rude to beginners like me... Now, how do you want me to prove that i'm
not
> asking you to do my homework...? Do you want me to sign a bond or
what?
> The only reason i came here was thinking that this is an open forum...
and
> thought i could ask for some help... Now, how do i show you my work if
I
> didn't even understand the problem... Anyway, I won't bother you guys
> again... You can talk all the hi fi stuff...
>
> And Admin Sir, Let me finally congratulate you in having such a
wonderful
> forum... All the above things were my personal opinions because i was
hurt
> a lot after posting here but your board is definitely helpful for many
> experienced programmers to interact... Keep it up Sir...
>
> purifier

douche-bag!

--
Mabden


Mabden

unread,
Jan 23, 2005, 8:05:22 AM1/23/05
to
"Mike Wahler" <mkwa...@mkwahler.net> wrote in message
news:5fUHd.1206$r27...@newsread1.news.pas.earthlink.net...

>
> The greatest of 2 is 2.
>

The greatest of 2 is 3, for relatively large values of 2...

--
Mabden


Mabden

unread,
Jan 23, 2005, 8:16:08 AM1/23/05
to
"CBFalconer" <cbfal...@yahoo.com> wrote in message
news:41ED6827...@yahoo.com...
> Since all potential homework problems are immeditately rejected or
> argued over for a week or so, the mechanism ensures that any
> homework answers arrive too late for submission, and thus do not
> exacerbate the flood of incompetent programmers.

Except those who research the archives!

...which has never happened, or they would have found last year's crop
of "Solve cold fishions without using fish or ions" problems'
"solutions".

Ah, reasearch. What ever happened to Rea, anyway?

--
Mabden


Mabden

unread,
Jan 23, 2005, 8:19:40 AM1/23/05
to
"Chris Dollin" <ke...@hpl.hp.com> wrote in message
news:csjbo1$cus$1...@malatesta.hpl.hp.com...

> Kenneth Brody wrote:
>
> > purifier wrote:
> >>
> >> The problem is to write a program in 'C' to find the greatest of 2
given
> >> numbers...

> >
> > By definition, you cannot find the "greatest" of two things.
>
> That's a pretty useless definition, then. Me, I can find the greatest
> of *one* thing. It's the greatest of *no* things that's tricky.

What is the greatest thing about pissing on your shoes?

The only thing I can think of is me doing it...

--
Mabden


Dave Thompson

unread,
Jan 23, 2005, 11:06:26 PM1/23/05
to
On Tue, 18 Jan 2005 15:58:57 +0000, Chris Dollin <ke...@hpl.hp.com>
wrote:

> Kenneth Brody wrote:
<snip>


> > By definition, you cannot find the "greatest" of two things.
>
> That's a pretty useless definition, then. Me, I can find the greatest
> of *one* thing. It's the greatest of *no* things that's tricky.

This is the difference between people and mathematicians. :-)

In Fortran MAXVAL of an empty (sub)array produces the identity, -huge,
and MINVAL respectively +huge. ISTR APL did essentially the same, but
that memory is faint and I have no reference at hand to check.

Now, the greatest (or whatever) of a *negative number* of things ...

And in those situations where one person says to another "I have a
little nothing for you" it definitely isn't no thing and usually is a
thing nowhere near least by the relevant metric(s). <G>

- David.Thompson1 at worldnet.att.net

0 new messages