Hello world without semicolon 
Author Message
 Hello world without semicolon

Hi,

I recently came across a puzzle that asked to write a Hello World program in C
without using a semicolon ..

Cant think of a way to do that... can anyone help ?

Thanks
Vipul Kapadia



Mon, 29 Nov 2004 20:19:04 GMT  
 Hello world without semicolon

Quote:
> Hi,
> I recently came across a puzzle that asked to write a Hello World program in C
> without using a semicolon ..
> Cant think of a way to do that... can anyone help ?

Without resorting to shameful dirty extremely-non-portable tricks such
as writing assembler code directly into the translation unit, the only
way that *I* can see this being done is:

#include <stdio.h>
#define semicolon ;
int main(void) {
  printf("Hello, world!\n") semicolon
  return 0 semicolon

Quote:
}

but I think that's cheating. Do digraphs and/or trigraphs help in this
puzzle?

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"That's no raisin - it's an ALIEN!"
   - Tourist in MTV's Oddities



Mon, 29 Nov 2004 20:25:18 GMT  
 Hello world without semicolon

Quote:

> I recently came across a puzzle that asked to write a Hello World
> program in C
> without using a semicolon ..

Are you allowed to use a -D option with the compiler?

$ cat myfile.c
#include <stdio.h>

int main(void)
{
   printf("Hello world\n") semi
   return 0 semi

Quote:
}

$ cc -Aa myfile.c -Dsemi=";"
$ ./a.out
Hello world
$

Even though I wrote it, I would not regard that as conforming to the
puzzle specification.

The code quoted herein is a non-corforming as a C program, for it
contains syntax errors.

Quote:
> Cant think of a way to do that... can anyone help ?

I think it is impossible.

Bill, or just improbable.



Mon, 29 Nov 2004 20:46:16 GMT  
 Hello world without semicolon
* Vipul Kapadia
| I recently came across a puzzle that asked to write a Hello World program in C
| without using a semicolon ..
|
| Cant think of a way to do that... can anyone help ?

  #include <stdio.h>

  int main()
  {
     if (puts("Hello, world."))
     {
     }
  }

Jeremy.



Mon, 29 Nov 2004 21:09:10 GMT  
 Hello world without semicolon
* Jeremy Yallop
|   #include <stdio.h>
|
|   int main()
|   {
|      if (puts("Hello, world."))

       if (puts("Hello, world.") != EOF)

|      {
|      }
|   }



Mon, 29 Nov 2004 21:12:29 GMT  
 Hello world without semicolon


Quote:
> Hi,

> I recently came across a puzzle that asked to write a Hello World program in C
> without using a semicolon ..

> Cant think of a way to do that... can anyone help ?

> Thanks
> Vipul Kapadia

#include <stdio.h>
int main()
{
   while( printf("Hello world\n") == 0 )
   {
   }
Quote:
}



Mon, 29 Nov 2004 23:04:08 GMT  
 Hello world without semicolon

Quote:
> * Vipul Kapadia
> | I recently came across a puzzle that asked to write a Hello World program in C
> | without using a semicolon ..
> |
> | Cant think of a way to do that... can anyone help ?
>   #include <stdio.h>
>   int main()
>   {
>      if (puts("Hello, world."))
>      {
>      }
>   }
> Jeremy.

I must say, that, and the one produced by "shmartonak", are pretty
clever. Why didn't *I* think of that?

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
   - Vampyra



Mon, 29 Nov 2004 23:39:23 GMT  
 Hello world without semicolon

Quote:


> > Hi,

> > I recently came across a puzzle that asked to write a Hello World program in C
> > without using a semicolon ..

> > Cant think of a way to do that... can anyone help ?

> Without resorting to shameful dirty extremely-non-portable tricks such
> as writing assembler code directly into the translation unit, the only
> way that *I* can see this being done is:

> #include <stdio.h>
> #define semicolon ;
> int main(void) {
>   printf("Hello, world!\n") semicolon
>   return 0 semicolon
> }

How about this:

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

int main( void )
{
    while( printf( "Hello, world!\n" ), exit( 0 ), 0 ) {}

Quote:
}

D.P.


Tue, 30 Nov 2004 01:36:58 GMT  
 Hello world without semicolon

Quote:
> * Vipul Kapadia
> | I recently came across a puzzle that asked to write a Hello World program in C
> | without using a semicolon ..
> |
> | Cant think of a way to do that... can anyone help ?

>   #include <stdio.h>

>   int main()
>   {
>      if (puts("Hello, world."))
>      {
>      }
>   }

> Jeremy.

You are missing the return statement. Once you put that in you need a
semicolon again. I was thinking you could use exit and the comma
operator. After a few seconds I realized that wouldn't work either.

---

"iqgbgxmdbjlgdv.lksrqek.n";char *strchr(const char *,int); while
(*i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);}return 0;}



Tue, 30 Nov 2004 01:33:48 GMT  
 Hello world without semicolon

Quote:

> * Vipul Kapadia

> | I recently came across a puzzle that asked to write a Hello World
> | program in C without using a semicolon ..
> |
> | Cant think of a way to do that... can anyone help ?

>   #include <stdio.h>

>   int main()
>   {
>      if (puts("Hello, world."))
>      {
>      }
>   }

Invalid in C99 - no return statement. or is it invalid in C90?

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Tue, 30 Nov 2004 01:49:38 GMT  
 Hello world without semicolon

Quote:


>> > Hi,

>> > I recently came across a puzzle that asked to write a Hello World program in C
>> > without using a semicolon ..

>> > Cant think of a way to do that... can anyone help ?

>> Without resorting to shameful dirty extremely-non-portable tricks such
>> as writing assembler code directly into the translation unit, the only
>> way that *I* can see this being done is:

>> #include <stdio.h>
>> #define semicolon ;
>> int main(void) {
>>   printf("Hello, world!\n") semicolon
>>   return 0 semicolon
>> }
> How about this:
> #include <stdio.h>
> #include <stdlib.h>
> int main( void )
> {
>     while( printf( "Hello, world!\n" ), exit( 0 ), 0 ) {}
> }
> D.P.

That's very nice. I guess the final ", 0" is needed because the type of
a while-expression can't be void. Does the C standard actually permit
an expression of type void on the left hand side of the comma operator?
BTW: This is dependent on how the implementation handles #inclusion of
<stdio.h> and <stdlib.h>. On most implementations, they are physical
files containing quite a lot of semicolons, since they have to
prototype all those functions, and a prototype without the actual
definition always includes a semicolon.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"You have moved your mouse, for these changes to take effect you must shut down
and restart your computer. Do you want to restart your computer now?"
   - Karri Kalpio



Tue, 30 Nov 2004 01:51:29 GMT  
 Hello world without semicolon

Quote:


>>* Vipul Kapadia
>>| I recently came across a puzzle that asked to write a Hello World program in C
>>| without using a semicolon ..
>>|
>>| Cant think of a way to do that... can anyone help ?

>>  #include <stdio.h>

>>  int main()
>>  {
>>     if (puts("Hello, world."))
>>     {
>>     }
>>  }

>>Jeremy.

> You are missing the return statement.

No, he's not missing it.

# If the return type of the main function is a type compatible with int,
# a return from the initial call to the main function is equivalent to
# calling the exit function with the value returned by the main function
# as its argument;9) reaching the } that terminates the main function
# returns a value of 0. If the return type is not compatible with int,
# the termination status returned to the host environment is unspecified.

Jirka



Tue, 30 Nov 2004 01:52:13 GMT  
 Hello world without semicolon

Quote:


>>* Vipul Kapadia

>>| I recently came across a puzzle that asked to write a Hello World
>>| program in C without using a semicolon ..
>>|
>>| Cant think of a way to do that... can anyone help ?

>>  #include <stdio.h>

>>  int main()
>>  {
>>     if (puts("Hello, world."))
>>     {
>>     }
>>  }

> Invalid in C99 - no return statement. or is it invalid in C90?

No. Yes.

Jirka



Tue, 30 Nov 2004 01:55:21 GMT  
 Hello world without semicolon

Quote:


>>   #include <stdio.h>

>>   int main()
>>   {
>>      if (puts("Hello, world."))
>>      {
>>      }
>>   }

> Invalid in C99 - no return statement. or is it invalid in C90?

No, and no.


Tue, 30 Nov 2004 02:05:14 GMT  
 Hello world without semicolon


Quote:


> >>* Vipul Kapadia
> >>| I recently came across a puzzle that asked to write a Hello World
program in C
> >>| without using a semicolon ..
> >>|
> >>| Cant think of a way to do that... can anyone help ?

> >>  #include <stdio.h>

> >>  int main()
> >>  {
> >>     if (puts("Hello, world."))
> >>     {
> >>     }
> >>  }

> >>Jeremy.

> > You are missing the return statement.

> No, he's not missing it.

> # If the return type of the main function is a type compatible with int,
> # a return from the initial call to the main function is equivalent to
> # calling the exit function with the value returned by the main function
> # as its argument;9) reaching the } that terminates the main function
> # returns a value of 0. If the return type is not compatible with int,
> # the termination status returned to the host environment is unspecified.

> Jirka

Then why do I bother adding return 0; to the end of main?

Is this only true for main?  What happens in this function?

int foo(void)
{
  do something but never return any value.

Quote:
}

Or this function

char foo(void)
{
  do something but never return any value.

Quote:
}

Sean


Tue, 30 Nov 2004 02:50:52 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Turing completion without semicolons?

2. a hello world encryption

3. Canocical hello world

4. The Program Only Harder Then Hello World...

5. Hello World not working

6. Hello World Problem

7. Newbie Question about Hello World

8. Hello World

9. Hello World

10. Hello World problems

11. Hello World Web service

12. Hello world!

 

 
Powered by phpBB® Forum Software