473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

without loop printing 1 to n

no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA

Dec 22 '06 #1
48 2345
jd

Yahooooooooo wrote:
no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA#
recusion?

void foo(int a, b) {
if(a=b) then return
else {
printf("%d\n", a);
foo(a+1, b);
}
}

Dec 22 '06 #2
Le 22-12-2006, Yahooooooooo <m.******@gmail.coma écrit*:
no gotos
no loops
how is it possbile.....
Asked in interview ...
recursion

Marc Boyer
Dec 22 '06 #3
jd

jd wrote:
Yahooooooooo wrote:
no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA#

recusion?

void foo(int a, b) {
if(a=b) then return
else {
printf("%d\n", a);
foo(a+1, b);
}
}
Whoops. Too hasty, == for equality, include stdio.h etc..

Dec 22 '06 #4
jd

jd wrote:
jd wrote:
Yahooooooooo wrote:
no gotos
no loops
how is it possbile.....
Asked in interview ...
>
Regards
MA#
recusion?

void foo(int a, b) {
if(a=b) then return
else {
printf("%d\n", a);
foo(a+1, b);
}
}

Whoops. Too hasty, == for equality, include stdio.h etc..
Bah! It gets worse! No 'then' obviously. Guess who has to program in
Delphi at the moment?

Dec 22 '06 #5
jd

jd wrote:
jd wrote:
jd wrote:
Yahooooooooo wrote:
no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA#
>
recusion?
>
void foo(int a, b) {
if(a=b) then return
else {
printf("%d\n", a);
foo(a+1, b);
}
}
Whoops. Too hasty, == for equality, include stdio.h etc..

Bah! It gets worse! No 'then' obviously. Guess who has to program in
Delphi at the moment?
AAARRRGHH! And it only prints up to N-1 too. Should have been a>b.

I promise I'll never post again to clc.

Dec 22 '06 #6
Yahooooooooo wrote:
>
no gotos
no loops
how is it possbile.....
Recursion.

--
pete
Dec 22 '06 #7
Yahooooooooo said:
no gotos
no loops
how is it possbile.....
Method 1 of N:

#include <stdio.h>

int main(void)
{
puts("1 to n");
return 0;
}

Method N of N:

#include <stdio.h>
#include <assert.h>

void printrange(unsigned long low, unsigned long high)
{
unsigned long range = 0;
assert(low <= high);
range = high - low + 1;
if(range 1)
{
unsigned long this = low + range / 2;
unsigned long lolo = low;
unsigned long lohi = this - 1;
unsigned long hihi = high;
unsigned long hilo = this + 1;

if(lolo <= lohi)
{
printrange(lolo, lohi);
}
printf(" %lu", this);
if(hilo <= hihi)
{
printrange(hilo, hihi);
}
}
else
{
printf(" %lu", high);
}
}

int main(void)
{
printrange(1UL, 1000UL); /* insert your own unsigned long value here */
putchar('\n');
return 0;
}

Finding methods 2 to N-1 is left as an exercise.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 22 '06 #8

Yahooooooooo wrote:
no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA


SORRY forgot to metion....
No recursion also :(

Dec 22 '06 #9
On 22 Dec 2006 03:29:29 -0800, "Yahooooooooo" <m.******@gmail.com>
wrote:
>
Yahooooooooo wrote:
>no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA

SORRY forgot to metion....
No recursion also :(

Not real recursion, but template recursion:

<code>
#include <iostream>

template <int M,int MAXstruct whatever {
ostream& intoStream(ostream& os) const {
os<<M;
if (M<MAX) os<<','<<whatever<M+1,MAX>();
return os;
}
};

template <int Mstruct whatever<M,M{
ostream& intoStream(ostream& os) const {
return os<<M;
}
};

template <int M,int MAX>
ostream& operator<<(ostream& os,const whatever<M,MAX>& thing)
{
return thing.intoStream(os);
}
int main() {
const int n=10;
std::cout<<whatever<1,n>()<<std::endl;
char c;std::cin>>c;
}
</code>

It is limited by your compiler limits on template recursion, and it is
a fixed program.

Regards,

Zara

Dec 22 '06 #10
On Fri, 22 Dec 2006 12:56:10 +0100, Zara <me*****@dea.spamcon.org>
wrote:
>On 22 Dec 2006 03:29:29 -0800, "Yahooooooooo" <m.******@gmail.com>
wrote:
>>
Yahooooooooo wrote:
>>no gotos
no loops
how is it possbile.....
Asked in interview ...
<..>
>
Not real recursion, but template recursion:
<...>

I am so sorry. I thought I was reading comp.lang.c++.

I hope no one will be disturbed by this unintended slip of C++ code
into C list. I swear I will try to aviod this kind of errors in the
future.

Best and sorrowful regards,

Zara
Dec 22 '06 #11
Zara said:
On 22 Dec 2006 03:29:29 -0800, "Yahooooooooo" <m.******@gmail.com>
wrote:
>>
Yahooooooooo wrote:
>>no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA

SORRY forgot to metion....
No recursion also :(


Not real recursion, but template recursion:

<code>
#include <iostream>
Non-standard header...
>
template <int M,int MAXstruct whatever {
....followed by syntax errors.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 22 '06 #12
Yahooooooooo wrote:
Yahooooooooo wrote:
>>no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA


SORRY forgot to metion....
No recursion also :(
longjmp, signal?

a+, ld.
Dec 22 '06 #13
Le 22-12-2006, Laurent Deniau <la************@cern.cha écrit*:
Yahooooooooo wrote:
>Yahooooooooo wrote:
>>>no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA


SORRY forgot to metion....
No recursion also :(

longjmp, signal?
pre-processor recursion also.

Marc Boyer
Dec 22 '06 #14


On Fri, 22 Dec 2006, Yahooooooooo wrote:
>
Yahooooooooo wrote:
>no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA

SORRY forgot to metion....
No recursion also :(


When hope has died... setjmp/longjmp save the day! I still agree that
technically it's a loop, but not a usual one ...;-)

Did I pass the interview?

Enjoy,

Emil
/*------------------------------------------------*/

#include <stdio.h>
#include <setjmp.h>

#define N 1000

static int curr_N = 0;

static jmp_buf jmpbuf;

void print(void)
{
curr_N++;
printf("%d\n",curr_N);
longjmp(jmpbuf,curr_N);
}
int main()
{
if (setjmp(jmpbuf) == N)
return 0;

print();

return 0; /* Just to prevent a compiler warning */
}
Dec 22 '06 #15
2006-12-22 <11**********************@48g2000cwx.googlegroups. com>,
jd wrote:
>
jd wrote:
>jd wrote:
jd wrote:
Yahooooooooo wrote:
no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA#

recusion?

void foo(int a, b) {
if(a=b) then return
else {
printf("%d\n", a);
foo(a+1, b);
}
}

Whoops. Too hasty, == for equality, include stdio.h etc..

Bah! It gets worse! No 'then' obviously. Guess who has to program in
Delphi at the moment?

AAARRRGHH! And it only prints up to N-1 too. Should have been a>b.

I promise I'll never post again to clc.
You missed a semicolon </piling on>
Dec 22 '06 #16
Marc Boyer wrote:
Le 22-12-2006, Laurent Deniau <la************@cern.cha écrit :
>>Yahooooooooo wrote:
>>>Yahooooooooo wrote:
no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA


SORRY forgot to metion....
No recursion also :(

longjmp, signal?


pre-processor recursion also.
no recursion ;-)

This would means that n is an integral constant literal and known at
compile-time and therefore would allow to expand the loop manually.

a+, ld.
Dec 22 '06 #17
Yahooooooooo wrote:
no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA
#include <stdio.h>

int main(void)
{
printf("1 to n\n");
return 0;
}

--
Clark S. Cox III
cl*******@gmail.com
Dec 22 '06 #18
Yahooooooooo wrote:
no gotos
no loops
how is it possbile.....
Asked in interview ...
...and lateron
No recursion also
Barring the typical ways to do this, i.e. some form of looping (using
for/while/goto) or recursion, there are pretty little choices left.

1. You could use a library function but I wouldn't be aware of one in the C
stdlib (more on that later).
2. You could use predefined, external data. For any Unixy system that boils
down to a system("seq ...") call or similar things.
3. Similarly, you could simply count external events, but there is no
construct that I'm aware of that lets you do that without somehow entering
a loop first...

Just wondering, are you sure that question was about C? Just for the
record, there are a few interesting ways in C++ that e.g. make use of
constructors or the C++ standardlibrary, which -other than the C one- does
have a function that can be used to generate sequences.

Anyhow, the notion of repeating anything with changed parameters until some
condition is fulfilled is called looping, no matter how you finally spell
it out and no matter where exactly the code is executed, so any of the
above methods don't qualify in the stricter sense.

The only thing that does not qualify as a loop is to spell it out (more or
less to unroll the loop):

if i 0
print 1
if i 1
print 2
if i 2
print 3
...

What did the interviewer expect?

Uli

Dec 22 '06 #19
"Yahooooooooo" <m.******@gmail.comwrote in message
news:11*********************@i12g2000cwa.googlegro ups.com...
no gotos
no loops
how is it possbile.....
Asked in interview ...
Most iterative problems can also be solved with recursion, and vice
versa. One or the other will be cleaner in most situations, but with a
bit of creativity you can transform one into the other.

#include <stdio.h>

void foo(unsigned n) {
if (!n) return;
foo(n-1);
printf("%u\n", n);
}

If you could print them from N to 1, instead of 1 to N, you could use a
slightly different form that a reasonably smart compiler could optimize
better (aka tail recursion).

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from http://www.teranews.com

Dec 22 '06 #20


On Fri, 22 Dec 2006, Ulrich Eckhardt wrote:
Yahooooooooo wrote:
>no gotos
no loops
how is it possbile.....
Asked in interview ...

..and lateron
>No recursion also
And how about this one? This is of course an unusual recursion, but I
think it's funny. Notice that here you are likely to be hit by a limit
imposed by the OS regarding the number of processes. Did I pass the
interview now? ;-))

Emil
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>

/* Make sure you define PROG_NAME to the name of your executable.
Using argv[0] is not portable */

#define PROG_NAME "print_1_to_n.exe"

#define N 100

int main(int argc, char *argv[])
{
/* Allocate 1 digit for every 3 bits, hopefully is enough */
char buffer[sizeof(PROG_NAME) +
(sizeof(int)*CHAR_BIT + 2)/3 +
1];
int n;

switch (argc) {
case 1:
n = 0;
break;

case 2:
/* Yeah I know, atoi() is bad, real programs should
should use strtol() and check for errors*/
n = atoi(argv[1]);
if (n <= 0) {
fprintf(stderr,"Wrong arguments\n");
exit(1);
}
break;

default:
fprintf(stderr,"Wrong arguments\n");
exit(1);
}

n++;

printf("%d\n",n);

if (n>=N)
return 0;

sprintf(buffer,"%s %d",PROG_NAME,n);

system(buffer);

return 0;
}
Dec 22 '06 #21
"jd" <jd*********@hotmail.comwrites:
jd wrote:
>jd wrote:
jd wrote:
Yahooooooooo wrote:
no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA#

recusion?

void foo(int a, b) {
if(a=b) then return
else {
printf("%d\n", a);
foo(a+1, b);
}
}

Whoops. Too hasty, == for equality, include stdio.h etc..

Bah! It gets worse! No 'then' obviously. Guess who has to program in
Delphi at the moment?

AAARRRGHH! And it only prints up to N-1 too. Should have been a>b.

I promise I'll never post again to clc.
No need for that. Just promise that you'll never post code without
compiling and executing it first.

--
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.
Dec 22 '06 #22
Kohn Emil Dan <em***@cs.technion.ac.ilwrites:
[...]
int main()
Better: int main(void)
{
[...]
return 0; /* Just to prevent a compiler warning */
No, this isn't just to prevent a compiler warning; it's to ensure that
your program returns a well-defined status to the environment. (The
"return 0;" is implicit in C99, but it doesn't hurt to have it
anyway.)
}
--
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.
Dec 22 '06 #23
Yahooooooooo wrote:
>no gotos
no loops
how is it possbile.....
Asked in interview ...

..and lateron
>No recursion also
Kohn Emil Dan <em***@cs.technion.ac.ilwrites:
And how about this one? This is of course an unusual recursion, but I
think it's funny. Notice that here you are likely to be hit by a limit
imposed by the OS regarding the number of processes. Did I pass the
interview now? ;-))

#include <stdio.h>
#include <limits.h>
#include <stdlib.h>

/* Make sure you define PROG_NAME to the name of your executable.
Using argv[0] is not portable */

#define PROG_NAME "print_1_to_n.exe"

#define N 100

int main(int argc, char *argv[])
{
/* Allocate 1 digit for every 3 bits, hopefully is enough */
char buffer[sizeof(PROG_NAME) +
(sizeof(int)*CHAR_BIT + 2)/3 +
1];
int n;

switch (argc) {
case 1:
n = 0;
break;

case 2:
/* Yeah I know, atoi() is bad, real programs should
should use strtol() and check for errors*/
n = atoi(argv[1]);
if (n <= 0) {
fprintf(stderr,"Wrong arguments\n");
exit(1);
}
break;

default:
fprintf(stderr,"Wrong arguments\n");
exit(1);
}

n++;

printf("%d\n",n);

if (n>=N)
return 0;

sprintf(buffer,"%s %d",PROG_NAME,n);

system(buffer);
On POSIX platforms one could even use:

#v+
sprintf(buffer, "%d", n);
execlp(PROG_NAME, argv[0], buffer, (char*)0);
#v-

And there would be no problems with the number of processes limit.
return 0;
}
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
Dec 23 '06 #24
On Fri, 22 Dec 2006 11:00:57 +0000, Richard Heathfield
<rj*@see.sig.invalidwrote:
>Yahooooooooo said:
>no gotos
no loops
how is it possbile.....

Method 1 of N:

#include <stdio.h>

int main(void)
{
puts("1 to n");
return 0;
}

Method N of N:

#include <stdio.h>
#include <assert.h>

void printrange(unsigned long low, unsigned long high)
The function name "printrange" has external linkage. As such, in order
to be strictly conforming to the C90 Standard, it must be significant
from any other external name in the first six characters. You're lucky
you didn't lose your temper and name it something like
"printfrigginrange" instead.

The latter name would, of course, collide with printf in the included
file <stdio.h>, and the result would be undefined behavior.

One convention to consider, in order to reduce the probablility of
this type of undefined behavior, is to have an underscore somwehere in
the second to sixth characters of your external name, especially if it
separates words.

As an example, consider this function prototype:

void printrange(unsigned long low, unsigned long high);

You can accomplish both of the tenets above by inserting a single
underscore after the fifth character of this function name, i.e.:

void print_range(unsigned long low, unsigned long high);

The big advantage is that someone in your audience doesn't have to
spend minutes or hours (or days or years or forever?) trying to figure
out if the author pronounced it: "PRiority INT RANGE" (the range of an
object of type int that represents a task priority); or "PRImary NT
RANGE" (The pasture where most computers still running Windows NT have
retired to); or "PRINTeR ANGE" (The angst you feel when you are
experiencing printer problems); and possibly others.

I've wasted a lot of time--no--authors have wasted a lot of my time,
by not using underscores in their names.

Have a Merry Christmas
--
jay

Dec 23 '06 #25
jaysome said:
On Fri, 22 Dec 2006 11:00:57 +0000, Richard Heathfield
<rj*@see.sig.invalidwrote:
<snip>
>>
void printrange(unsigned long low, unsigned long high)

The function name "printrange" has external linkage. As such, in order
to be strictly conforming to the C90 Standard, it must be significant
from any other external name in the first six characters.
And it is.
You're lucky you didn't lose your temper and name it something like
"printfrigginrange" instead.

The latter name would, of course, collide with printf in the included
file <stdio.h>, and the result would be undefined behavior.
But I didn't call it that, so I don't see what point you are failing to
make.

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 23 '06 #26


On Fri, 22 Dec 2006, Keith Thompson wrote:
Kohn Emil Dan <em***@cs.technion.ac.ilwrites:
[...]
>int main()

Better: int main(void)
Correct.
>
>{
[...]
> return 0; /* Just to prevent a compiler warning */

No, this isn't just to prevent a compiler warning; it's to ensure that
your program returns a well-defined status to the environment. (The
"return 0;" is implicit in C99, but it doesn't hurt to have it
anyway.)
The point is that the code will never reach that return statement, as far
as I can see. main() will always return via the return statement
controlled by if (setjmp(...)) Therefore I think that the return statement
could have been omitted, but I placed it because I don't think that the
compiler can figure out that it will never be reached.
Emil
>
>}

--
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.
Dec 23 '06 #27
Kohn Emil Dan said:
On Fri, 22 Dec 2006, Keith Thompson wrote:
>Kohn Emil Dan <em***@cs.technion.ac.ilwrites:
<snip>
>> return 0; /* Just to prevent a compiler warning */

No, this isn't just to prevent a compiler warning; it's to ensure that
your program returns a well-defined status to the environment. (The
"return 0;" is implicit in C99, but it doesn't hurt to have it
anyway.)

The point is that the code will never reach that return statement, as far
as I can see.
What has that to do with anything? It's a question of good programming
practice.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 23 '06 #28
Richard Heathfield wrote:
Kohn Emil Dan said:
On Fri, 22 Dec 2006, Keith Thompson wrote:
Kohn Emil Dan <em***@cs.technion.ac.ilwrites:

<snip>
> return 0; /* Just to prevent a compiler warning */

No, this isn't just to prevent a compiler warning; it's to ensure that
your program returns a well-defined status to the environment. (The
"return 0;" is implicit in C99, but it doesn't hurt to have it
anyway.)
The point is that the code will never reach that return statement, as far
as I can see.

What has that to do with anything?
Well, if the code never reaches that return statement, the program
returns a well-defined status regardless of whether that return
statement is present, so it /is/ just there to prevent a compiler
warning.
It's a question of good programming
practice.
So you support adding dead code to programs just because it would be
useful or good practice if it weren't dead code?

Dec 23 '06 #29
Harald van D?k said:
Richard Heathfield wrote:
<snip>
>It's a question of good programming practice.

So you support adding dead code to programs just because it would be
useful or good practice if it weren't dead code?
I support defence in depth. When, one day, all that longjmp/setjmp nonsense
is removed and the program produces its output sensibly, it would be nice
not to have to remember to fix up main to return a proper value to its
caller.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 23 '06 #30
Richard Heathfield wrote:
Harald van D?k said:
Richard Heathfield wrote:

<snip>
It's a question of good programming practice.
So you support adding dead code to programs just because it would be
useful or good practice if it weren't dead code?

I support defence in depth. When, one day, all that longjmp/setjmp nonsense
is removed and the program produces its output sensibly, it would be nice
not to have to remember to fix up main to return a proper value to its
caller.
How far are you willing to take that? Would you remove the final return
statement in

int main(void) {
if(...) return EXIT_SUCCESS;
else return EXIT_FAILURE;

return 0;
}

And how about this?

void func(void) { if(...) exit(0); }
int main(void) {
for(;;) func();

return 0;
}

Dec 23 '06 #31
Harald van D?k said:
Richard Heathfield wrote:
>Harald van D?k said:
<snip>
>
So you support adding dead code to programs just because it would be
useful or good practice if it weren't dead code?

I support defence in depth. When, one day, all that longjmp/setjmp
nonsense is removed and the program produces its output sensibly, it
would be nice not to have to remember to fix up main to return a proper
value to its caller.

How far are you willing to take that? Would you remove the final return
statement in

int main(void) {
if(...) return EXIT_SUCCESS;
else return EXIT_FAILURE;

return 0;
}
No, I'd remove the other two returns:

int main(void)
{
int rc = EXIT_FAILURE;
if(...)
{
rc = EXIT_SUCCESS;
}

return rc;
}
>
And how about this?

void func(void) { if(...) exit(0); }
int main(void) {
for(;;) func();

return 0;
}
int func(void)
{
int rc = 0;
if(...)
{
rc = 1;
}
return rc;
}

int main(void)
{
while(func() == 0)
{
continue;
}

return 0;
}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 23 '06 #32
Richard Heathfield wrote:
Harald van D?k said:
Richard Heathfield wrote:
Harald van D?k said:
<snip>

So you support adding dead code to programs just because it would be
useful or good practice if it weren't dead code?

I support defence in depth. When, one day, all that longjmp/setjmp
nonsense is removed and the program produces its output sensibly, it
would be nice not to have to remember to fix up main to return a proper
value to its caller.
How far are you willing to take that? Would you remove the final return
statement in

int main(void) {
if(...) return EXIT_SUCCESS;
else return EXIT_FAILURE;

return 0;
}

No, I'd remove the other two returns:

int main(void)
{
int rc = EXIT_FAILURE;
if(...)
{
rc = EXIT_SUCCESS;
}

return rc;
}

And how about this?

void func(void) { if(...) exit(0); }
int main(void) {
for(;;) func();

return 0;
}

int func(void)
{
int rc = 0;
if(...)
{
rc = 1;
}
return rc;
}

int main(void)
{
while(func() == 0)
{
continue;
}

return 0;
}
So basically, you prefer to always have main() return via a return
statement at the end of the function, possibly barring any exceptional
conditions that make this (nearly) impossible? If so, fair enough, but
that's a personal choice, and not the only way to write clear and clean
programs.

Dec 23 '06 #33
Harald van D?k said:

<snip>
So basically, you prefer to always have main() return via a return
statement at the end of the function,
Yes. Since main is defined as returning int, it seems only right and proper
to return an int from main.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 23 '06 #34
On Sat, 23 Dec 2006 18:04:15 +0000, Richard Heathfield
<rj*@see.sig.invalidwrote:
>Harald van D?k said:
>Richard Heathfield wrote:

<snip>
>>It's a question of good programming practice.

So you support adding dead code to programs just because it would be
useful or good practice if it weren't dead code?

I support defence in depth. When, one day, all that longjmp/setjmp nonsense
is removed and the program produces its output sensibly, it would be nice
not to have to remember to fix up main to return a proper value to its
caller.
What about exit()?

#include <stdlib.h>
int main()
{
exit(0);
return 0;/*useless statement*/
}

--
jay
Dec 24 '06 #35
jaysome said:
On Sat, 23 Dec 2006 18:04:15 +0000, Richard Heathfield
<rj*@see.sig.invalidwrote:
>>Harald van D?k said:
>>Richard Heathfield wrote:

<snip>
>>>It's a question of good programming practice.

So you support adding dead code to programs just because it would be
useful or good practice if it weren't dead code?

I support defence in depth. When, one day, all that longjmp/setjmp
nonsense is removed and the program produces its output sensibly, it would
be nice not to have to remember to fix up main to return a proper value to
its caller.

What about exit()?

#include <stdlib.h>
int main()
{
exit(0);
return 0;/*useless statement*/
}
Close, but no banana. Here, I have removed the truly useless statement:

int main()
{
return 0;
}

:-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 24 '06 #36
In article <a_*********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
....
>Close, but no banana. Here, I have removed the truly useless statement:

int main()
{
return 0;
}
I believe the well-known phrase is:

Never argue with a Richard Heathfield.
It will bring you down to its level and then beat you with experience.

Dec 24 '06 #37
Keith Thompson <ks***@mib.orgwrites:
Kohn Emil Dan <em***@cs.technion.ac.ilwrites:
[...]
>int main()

Better: int main(void)
>{
[...]
> return 0; /* Just to prevent a compiler warning */

No, this isn't just to prevent a compiler warning; it's to ensure that
your program returns a well-defined status to the environment. (The
"return 0;" is implicit in C99, but it doesn't hurt to have it
anyway.)
>}
When I wrote the above, I didn't realize that the "return 0;" at the
end of main() is never reached.

--
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.
Dec 24 '06 #38
On 22 Dec 2006 02:36:04 -0800, "Yahooooooooo" <m.******@gmail.com>
wrote:
>no gotos
no loops
how is it possbile.....
Asked in interview ...

Regards
MA
Since 1 to any non-negative power is equal to 1 just print 1

Oz
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 30 '06 #39
av
On Sat, 30 Dec 2006 06:58:58 GMT, ozbear wrote:
ON TOP-POSTING
so why is so wrong read in reverse order?
more near to the top more near to now, and the part much important is
in the top so i not have not scroll all text
>Oz
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 30 '06 #40
av said:
On Sat, 30 Dec 2006 06:58:58 GMT, ozbear wrote:
ON TOP-POSTING
so why is so wrong read in reverse order?
,sdrawkcab daer ot elbissop si ti ,seY .elihw a rof ti yrT
?redrah ksat 'sredaer ruoy ekam yhW .tluciffid ylirassecennu si ti tub
more near to the top more near to now, and the part much important is
in the top so i not have not scroll all text
If you learned to snip unnecessary context, there would be almost no text to
scroll.

But if ordinary common sense doesn't persuade you, let's try enlightened
self-interest. When you need help from people in this channel, would you
rather have the help of the bright people or the stupid people? The bright
people like to read stuff the right way up, and they like to see just
enough context to make sense, not pageloads of junk. And when a subscriber
writes upside down over and over and over again, many of the bright people
get sick and tired of it, and just ignore articles from that subscriber.

Top-posting is not a good strategy for those who need Usenet as a learning
resource.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 30 '06 #41
Richard Heathfield wrote:
av said:
.... snip ...
>
,sdrawkcab daer ot elbissop si ti ,seY .elihw a rof ti yrT
?redrah ksat 'sredaer ruoy ekam yhW .tluciffid ylirassecennu si ti tub
>more near to the top more near to now, and the part much important
is in the top so i not have not scroll all text

If you learned to snip unnecessary context, there would be almost
no text to scroll.

But if ordinary common sense doesn't persuade you, let's try
enlightened self-interest. When you need help from people in this
channel, would you rather have the help of the bright people or
the stupid people? The bright people like to read stuff the right
way up, and they like to see just enough context to make sense,
not pageloads of junk. And when a subscriber writes upside down
over and over and over again, many of the bright people get sick
and tired of it, and just ignore articles from that subscriber.

Top-posting is not a good strategy for those who need Usenet as a
learning resource.
av has long been PLONKED here for refusal to follow normal
protocol.

--
Some informative links:
<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>
<http://cfaj.freeshell.org/google/>
Dec 30 '06 #42
CBFalconer wrote:
av has long been PLONKED here for refusal to follow normal
protocol.
Have you tried the first link from your signature,
http://www.geocities.com/nnqweb/ ? Do try it and count
number of additional clicks needed to get to the actual
stuff and how many advertisements you get on the way there.

Regards,
Yevgen
Dec 31 '06 #43
Yevgen Muntyan wrote:
CBFalconer wrote:
>av has long been PLONKED here for refusal to follow normal
protocol.

Have you tried the first link from your signature,
http://www.geocities.com/nnqweb/ ? Do try it and count
number of additional clicks needed to get to the actual
stuff and how many advertisements you get on the way there.
Not for a long time. I'll check, and possibly remove it.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Dec 31 '06 #44
Yevgen Muntyan wrote:
CBFalconer wrote:
>av has long been PLONKED here for refusal to follow normal
protocol.

Have you tried the first link from your signature,
http://www.geocities.com/nnqweb/ ? Do try it and count
number of additional clicks needed to get to the actual
stuff and how many advertisements you get on the way there.
Just tried it and no great problem. The linked page has a
"suppress ads" button, and I have many ads avoided through a hosts
file, so my experience may not be typical. I revised that sig to
avoid the redirection step.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Dec 31 '06 #45
CBFalconer wrote:
Yevgen Muntyan wrote:
>>CBFalconer wrote:

>>>av has long been PLONKED here for refusal to follow normal
protocol.

Have you tried the first link from your signature,
http://www.geocities.com/nnqweb/ ? Do try it and count
number of additional clicks needed to get to the actual
stuff and how many advertisements you get on the way there.


Just tried it and no great problem. The linked page has a
"suppress ads" button, and I have many ads avoided through a hosts
file, so my experience may not be typical. I revised that sig to
avoid the redirection step.
Well, here's my trip to the destination:
http://munt.mine.nu:8080/files/ss/

Now I understand, I should have clicked "Next Page" button hidden
in the bottom of the first page instead of "selecting a mirror"
as it asked me. Though in this case I get popup windows while the
first way is popup-less but longer. Anyway, point was: if a person
gets *that* as a response "why not top-post, i like it", then he
probably thinks "Is this junk supposed to mean anything?" instead
of "Oops, my bad, learning this valuable stuff right away to become
a great citizen of the world!"
And then you wonder why people don't want to be cool and why they
ignore Some informative links.

Happy New Year anyway, only five hours left!
Yevgen
Dec 31 '06 #46
CBFalconer said:
Yevgen Muntyan wrote:
>CBFalconer wrote:
>>av has long been PLONKED here for refusal to follow normal
protocol.

Have you tried the first link from your signature,
http://www.geocities.com/nnqweb/ ? Do try it and count
number of additional clicks needed to get to the actual
stuff and how many advertisements you get on the way there.

Not for a long time. I'll check, and possibly remove it.
Might be a good idea. The advertisements load quickly but, in Konqueror at
least, the rest of the page remains blank, the wheel keeps turning, and
Nothing Happens (tm). I have no idea what's *supposed* to be on the page,
but all I *see* is whitespace and advertisements.

So - on to Galeon, and this time I see the following:

"Welcome to the news.newusers.questions Official Home Page in
[Site Location]
[IMPORTANT INFORMATION]

Since Yahoo!GeoCities terminated our ability to use FTP access to manage the
files on our website, we have moved this site to

http://members.fortunecity.com/nnqweb/

Please update your bookmarks."

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 31 '06 #47
On Sun, 31 Dec 2006 07:14:06 GMT, in comp.lang.c , Yevgen Muntyan
<mu****************@tamu.eduwrote:
>Happy New Year anyway, only five hours left!
The wonders of time zones. 15 hours.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Dec 31 '06 #48
Yevgen Muntyan wrote:
CBFalconer wrote:
>Yevgen Muntyan wrote:
>>CBFalconer wrote:

av has long been PLONKED here for refusal to follow normal
protocol.

Have you tried the first link from your signature,
http://www.geocities.com/nnqweb/ ? Do try it and count
number of additional clicks needed to get to the actual
stuff and how many advertisements you get on the way there.

Just tried it and no great problem. The linked page has a
"suppress ads" button, and I have many ads avoided through a hosts
file, so my experience may not be typical. I revised that sig to
avoid the redirection step.

Well, here's my trip to the destination:
http://munt.mine.nu:8080/files/ss/

Now I understand, I should have clicked "Next Page" button hidden
in the bottom of the first page instead of "selecting a mirror"
as it asked me. Though in this case I get popup windows while the
first way is popup-less but longer. Anyway, point was: if a person
gets *that* as a response "why not top-post, i like it", then he
probably thinks "Is this junk supposed to mean anything?" instead
of "Oops, my bad, learning this valuable stuff right away to become
a great citizen of the world!"
And then you wonder why people don't want to be cool and why they
ignore Some informative links.
Here is the revised sig and link. Now how does it play? I am
using firefox 2.0 with popups disabled and the aforesaid hosts
file. Things are happy here using either 'nextpage' or selecting
various mirrors.

--
Some informative links:
<http://members.fortunecity.com/nnqweb/ (newusers)
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/ (taming google)

Dec 31 '06 #49

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: hari krishna | last post by:
hi all, My requirement is to generate xl reports throu Asp.Net without installing xl on web server computer. i am using Response object and wrtifile method as below. i dont know whether it is...
11
by: Roman Töngi | last post by:
for (int i = 1; i <= 10; i++) cout << i << endl; I expected the following: 1 2 3 4 5 6
4
by: Al Jones | last post by:
Well, hopefully that title get someones attention. In this old gwbasic program I've converted I *have* sucessuflly converted it to print to a file and the output is acceptable. From there I have...
3
by: John Peterson | last post by:
Hello all! I'm at my wits end trying to search for what I assumed to be a relatively straightforward task. I have a Web application written in C#, and I have a button on the form that I want to...
6
by: placid | last post by:
Hi all, Im using the cmd module and i have command that loops and keeps on printing text, what i want to be able to do is loop until the user presses a particular key, say Q/q ? I tried the...
14
by: dba_222 | last post by:
Dear experts, Again, sorry to bother you again with such a seemingly dumb question, but I'm having some really mysterious results here. ie. Create procedure the_test As
2
by: Mike Purvis | last post by:
Hi, I have an app that opens Word docs, prints data into them, then it prints the doc then closes the doc. It does this in a loop. The program works fine, I just can't stop it while it is...
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
18
by: Vijaykumar Dave | last post by:
I have a program for base X power N as under. The problem is that when the range specified in loop is given it works well, but when any character is pressed, it goes to infinite loop. Second...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.