Hi,
Can any body tell me how to print "hello,world" with out using semicolon
Thanks in advance ..
Bye
Prashanth Badabagni 42 9828 b_*********@hotmail.com (Prashanth Badabagni) writes: Can any body tell me how to print "hello,world" with out using semicolon
"hello,world" doesn't contain a semicolon.
Prashanth Badabagni wrote: Hi, Can any body tell me how to print "hello,world" with out using semicolon
Yes. Now ask someone to help you search the archives at groups.google.com. b_*********@hotmail.com (Prashanth Badabagni) wrote in message news:<d1**************************@posting.google. com>... Hi, Can any body tell me how to print "hello,world" with out using semicolon Thanks in advance .. Bye Prashanth Badabagni
#include<stdio.h>
void main()
{
if(printf("hello world\n"))
} ma********@yahoo.com (madhukar_bm) wrote: b_*********@hotmail.com (Prashanth Badabagni) wrote in message news:<d1**************************@posting.google. com>... Can any body tell me how to print "hello,world" with out using semicolon
#include<stdio.h>
void main() { if(printf("hello world\n")) }
You _did_ compile this, I suppose?
Richard
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
madhukar_bm wrote: b_*********@hotmail.com (Prashanth Badabagni) wrote in message
news:<d1**************************@posting.google. com>...Hi, Can any body tell me how to print "hello,world" with out using semicolon Thanks in advance .. Bye Prashanth Badabagni
#include<stdio.h>
Whilst this line, of itself, does not contain a semicolon, it's actions
effectively insert many other lines (some of which /may/ contain semicolons)
into the source code. This is line technically satisfies the OPs requirement,
but operationally may not. void main()
In a hosted implementation, main() returns int, and must be declared so, unless
an implementation-specific extension is in use. No such extension has been
mentioned, and the OPs question does not specify an unhosted implementation, so
this line is suspect.
{ if(printf("hello world\n"))
An if() statement requires the inclusion of at least one additional statement,
to be executed when the if() evaluates to true. Your code above is a syntax
error at the very least.
Also, main() returns int. Ensure that int is returned. }
Alternatively, given a C99-compliant compiler for a hosted environment...
int main(void)
{
if (printf("hello, world\n")) {}
}
/*
** In the absence of a prototype, the printf() function is
** assumed to return int and to take as its argument
** a single string. Both of these assumptions are consistant
** with the function declaration found in stdio.h, and thus
** while fragile and technically suspect, is acceptable.
** The absence of the stdio include eliminates the possibility
** of included semicolons, and satisfies the argument against
** the use of an included header in /this/ program.
**
** The if() statement is satisfied by an empty compound statement,
** correcting the previous poster's syntax error.
**
** Finally, as the main() function is defined as returning int, and
** this is specified to be compiled in a C99-compliant compiler for
** a hosted environment, the language environment will ensure that
** an appropriate int value is returned from main() in the absence
** of an explicit value return.
*/
- --
Lew Pitcher
IT Consultant, Enterprise Application Architecture,
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
iD8DBQFAljs6agVFX4UWr64RAhvyAKCqIs5ZG0a3SOnnzjBhIy VtXgcgqACePvBS
mcMg7GKVMllpnd7ezuwi+g4=
=8u1d
-----END PGP SIGNATURE-----
Lew Pitcher wrote: Alternatively, given a C99-compliant compiler for a hosted environment...
int main(void) { if (printf("hello, world\n")) {} }
No C99-compliant compiler is required to accept this program, since
there is no declaration in scope for printf().
/* ** In the absence of a prototype, the printf() function is ** assumed to return int and to take as its argument ** a single string. Both of these assumptions are consistant ** with the function declaration found in stdio.h, and thus ** while fragile and technically suspect, is acceptable.
No, calling a function that accepts a variable number of arguments
through a function pointer of non-variadic type invokes undefined
behaviour.
6 If the expression that denotes the called function has a type that
does not include a prototype, the integer promotions are performed
on each argument, and arguments that have type float are promoted
to double. [...] If the function is defined with a type that
includes a prototype, and either the prototype ends with an
ellipsis (, ...) or the types of the arguments after promotion
are not compatible with the types of the parameters, the behavior
is undefined. [C99 6.5.2.2]
If you want to rely on an "implicit declaration" (using a C89
compiler), you can use puts() instead.
Jeremy.
On Mon, 2 May 2004, Prashanth Badabagni wrote: Hi, Can any body tell me how to print "hello,world" with out using semicolon
Yes, you go to http://www.google.ca/grphp and search for
"group:comp.lang.c hello world no semicolon".
--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@whitehouse.gov
"Prashanth Badabagni" <b_*********@hotmail.com> wrote in message
news:d1**************************@posting.google.c om... Hi, Can any body tell me how to print "hello,world" with out using
semicolon
Thanks in advance .. Bye Prashanth Badabagni
why would you want to?
Allan
On Mon, 3 May 2004, Thomas Matthews wrote: Prashanth Badabagni wrote:
Hi, Can any body tell me how to print "hello,world" with out using semicolon Thanks in advance .. Bye Prashanth Badabagni Besides being a homework candidate question, what useful application does this suit?
During an interview it could be a useful way to see of the candidate has
been lurking on comp.lang.c for the passed year or at least read the
archives. 8^)
I've never concerned myself with this kind of issue in all my 30 years of programming.
Only 21 years but I agree. I do occasionally have to understand some
obfuscated code however. I don't write obfuscated code (at least not for
professional programming) but I have had to re-write obfuscated code.
-- Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt C++ Faq: http://www.parashift.com/c++-faq-lite C Faq: http://www.eskimo.com/~scs/c-faq/top.html alt.comp.lang.learn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html Other sites: http://www.josuttis.com -- C++ STL Library book
--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@whitehouse.gov
In article <Pi*******************************@drj.pf>, da*****@NOMORESPAMcs.utoronto.ca.com (Darrell Grainger) wrote: On Mon, 2 May 2004, Prashanth Badabagni wrote:
Hi, Can any body tell me how to print "hello,world" with out using semicolon
Yes, you go to http://www.google.ca/grphp and search for "group:comp.lang.c hello world no semicolon".
A very simple solution is to write a BASIC program and run it:
10 PRINT "hello,world"
20 END
Even simpler, use a word processor, type "hello,world", then use the
Print menu.
On Tue, 4 May 2004, Christian Bau wrote: In article <Pi*******************************@drj.pf>, da*****@NOMORESPAMcs.utoronto.ca.com (Darrell Grainger) wrote:
On Mon, 2 May 2004, Prashanth Badabagni wrote:
Hi, Can any body tell me how to print "hello,world" with out using semicolon
Yes, you go to http://www.google.ca/grphp and search for "group:comp.lang.c hello world no semicolon".
A very simple solution is to write a BASIC program and run it:
10 PRINT "hello,world" 20 END
Even simpler, use a word processor, type "hello,world", then use the Print menu.
But then it would be off-topic for comp.lang.c. 8^)
--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@whitehouse.gov
Lew Pitcher <Le*********@td.com> scribbled the following: madhukar_bm wrote: b_*********@hotmail.com (Prashanth Badabagni) wrote in message news:<d1**************************@posting.google. com>...Hi, Can any body tell me how to print "hello,world" with out using semicolon
#include<stdio.h>
Whilst this line, of itself, does not contain a semicolon, it's actions effectively insert many other lines (some of which /may/ contain semicolons) into the source code. This is line technically satisfies the OPs requirement, but operationally may not.
If all that is needed is for the actual C source file not to contain
semicolons, all we need to do is:
/* file: program.c */
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}
/* file: main.c */
#include "program.c"
And then compile main.c.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It was, er, quite bookish."
- Horace Boothroyd b_*********@hotmail.com (Prashanth Badabagni) wrote in message news:<d1**************************@posting.google. com>... Can any body tell me how to print "hello,world" with out using semicolon
These requirements are easily satisfied with a one-line C translation
unit:
#error "hello,world"
since they don't specify that "hello,world" (or "hello , wolrd", or
other variations thereof) be printed during program execution, or
indeed that there be a program (written by the user to satisfy the
assignment) at all.
--
Michael Wojcik mi************@microfocus.com
An intense imaginative activity accompanied by a psychological and moral
passivity is bound eventually to result in a curbing of the growth to
maturity and in consequent artistic repetitiveness and stultification.
-- D. S. Savage mw*****@newsguy.com (Michael Wojcik) wrote in message news:<c7*********@news2.newsguy.com>... since they don't specify that "hello,world" (or "hello , wolrd", or other variations thereof) be printed during program execution, or indeed that there be a program (written by the user to satisfy the assignment) at all.
Since there is no requriement for even a program to be written:
(from the command line)
echo "hello, world"
In article <96**********************@posting.google.com>, re********@yahoo.com (red floyd) writes: Since there is no requriement for even a program to be written:
(from the command line) echo "hello, world"
Ah, but that's not topical on c.l.c, unlike my proposal. I'm treating
group topicality as an additional, externally-imposed requirement.
--
Michael Wojcik mi************@microfocus.com b_*********@hotmail.com (Prashanth Badabagni) wrote: Can any body tell me how to print "hello,world" with out using semicolon
Here is a variation: write C program to print ";"
without using semicolon, digits, double quote, and single quote.
Assume ascii.
Yakov
Yakov Lerner <ji******@yahoo.com> scribbled the following: b_*********@hotmail.com (Prashanth Badabagni) wrote: Can any body tell me how to print "hello,world" with out using semicolon
Here is a variation: write C program to print ";" without using semicolon, digits, double quote, and single quote. Assume ascii.
Earlier, I wrote a program to print "Hello, world" without using literal
values (numbers, characters or strings) at all. It also assumed ASCII.
By combining this and various techniques presented in this thread your
problem can be solved.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Show me a good mouser and I'll show you a cat with bad breath."
- Garfield
On Mon, 10 May 2004, Yakov Lerner wrote: b_*********@hotmail.com (Prashanth Badabagni) wrote: Can anybody tell me how to print "hello,world" without using semicolon
Here is a variation: write C program to print ";" without using semicolon, digits, double quote, and single quote. Assume ascii.
ASCII is off-topic in comp.lang.c. I think you meant to say,
"Do not assume ASCII."
#include <stdio.h>
#include <stdlib.h>
#define Z ((int)NULL)
#define P(x) printf(#x
#define L(x) #x
#define S L(| |)[!Z]
int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f
(++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z
&&P(%c%c%d\n),S,S,Z)&&f(++i,i)){}else if(--l==Z&&P(%c/\n),S
)&&f(++i,i)){}else if(exit(Z),Z){}}int main(){if(f(Z,Z)){}}
-Arthur
Arthur J. O'Dwyer <aj*@nospam.andrew.cmu.edu> scribbled the following: On Mon, 10 May 2004, Yakov Lerner wrote: b_*********@hotmail.com (Prashanth Badabagni) wrote: > Can anybody tell me how to print "hello,world" without using semicolon Here is a variation: write C program to print ";" without using semicolon, digits, double quote, and single quote. Assume ascii.
ASCII is off-topic in comp.lang.c. I think you meant to say, "Do not assume ASCII."
#include <stdio.h> #include <stdlib.h> #define Z ((int)NULL) #define P(x) printf(#x #define L(x) #x #define S L(| |)[!Z] int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f (++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z &&P(%c%c%d\n),S,S,Z)&&f(++i,i)){}else if(--l==Z&&P(%c/\n),S )&&f(++i,i)){}else if(exit(Z),Z){}}int main(){if(f(Z,Z)){}}
No fair with preprocessor trickery! When preprocessed, that code will
contain plenty of double quotes. If I'm allowed to assume ASCII, I can
write a program to do it containing double quotes only in standard
headers, even after preprocessing.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Immanuel Kant but Genghis Khan."
- The Official Graffitist's Handbook
Joona I Palaste <pa*****@cc.helsinki.fi> writes: Arthur J. O'Dwyer <aj*@nospam.andrew.cmu.edu> scribbled the following: On Mon, 10 May 2004, Yakov Lerner wrote: b_*********@hotmail.com (Prashanth Badabagni) wrote: > Can anybody tell me how to print "hello,world" without using semicolon Here is a variation: write C program to print ";" without using semicolon, digits, double quote, and single quote. Assume ascii.
ASCII is off-topic in comp.lang.c. I think you meant to say, "Do not assume ASCII."
#include <stdio.h> #include <stdlib.h> #define Z ((int)NULL) #define P(x) printf(#x #define L(x) #x #define S L(| |)[!Z] int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f (++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z &&P(%c%c%d\n),S,S,Z)&&f(++i,i)){}else if(--l==Z&&P(%c/\n),S )&&f(++i,i)){}else if(exit(Z),Z){}}int main(){if(f(Z,Z)){}}
No fair with preprocessor trickery! When preprocessed, that code will contain plenty of double quotes. If I'm allowed to assume ASCII, I can write a program to do it containing double quotes only in standard headers, even after preprocessing.
If I can assume ASCII, it's easy to do without using any preprocessor
facilities at all:
int main(void) { if (putchar((((main==main)+(main==main))*((main==
main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+
(main==main))* ((main==main)+(main==main)) * ((main==main)+(main==
main)))-(((main==main)+(main==main))*((main==main)+(main== main)))-
(main==main)), putchar((((main==main)+(main==main))*((main==main) +
(main==main)) * ((main==main)+(main==main)))+((main==main)+(main==
main))),exit(main!=main),main==main){}}
Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Martin Dickopp <ex****************@zero-based.org> scribbled the following: Joona I Palaste <pa*****@cc.helsinki.fi> writes: Arthur J. O'Dwyer <aj*@nospam.andrew.cmu.edu> scribbled the following: On Mon, 10 May 2004, Yakov Lerner wrote: b_*********@hotmail.com (Prashanth Badabagni) wrote: > Can anybody tell me how to print "hello,world" without using semicolon Here is a variation: write C program to print ";" without using semicolon, digits, double quote, and single quote. Assume ascii. ASCII is off-topic in comp.lang.c. I think you meant to say, "Do not assume ASCII."
#include <stdio.h> #include <stdlib.h> #define Z ((int)NULL) #define P(x) printf(#x #define L(x) #x #define S L(| |)[!Z] int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f (++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z &&P(%c%c%d\n),S,S,Z)&&f(++i,i)){}else if(--l==Z&&P(%c/\n),S )&&f(++i,i)){}else if(exit(Z),Z){}}int main(){if(f(Z,Z)){}}
No fair with preprocessor trickery! When preprocessed, that code will contain plenty of double quotes. If I'm allowed to assume ASCII, I can write a program to do it containing double quotes only in standard headers, even after preprocessing.
If I can assume ASCII, it's easy to do without using any preprocessor facilities at all:
int main(void) { if (putchar((((main==main)+(main==main))*((main== main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+ (main==main))* ((main==main)+(main==main)) * ((main==main)+(main== main)))-(((main==main)+(main==main))*((main==main)+(main== main)))- (main==main)), putchar((((main==main)+(main==main))*((main==main) + (main==main)) * ((main==main)+(main==main)))+((main==main)+(main== main))),exit(main!=main),main==main){}}
That's pretty clever. My original program to print "Hello, world"
without using literal values was pretty much the same way, except it
used a static variable and its negation to form 0 and 1, and then use
those to form all other natural numbers. I dare you to write a "Hello,
world" program in the way you are doing above. It won't require
particularly ingenious thinking but it will be tedious to type out.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"B-but Angus! You're a dragon!"
- Mickey Mouse
Martin Dickopp wrote: int main(void) { if (putchar((((main==main)+(main==main))*((main== main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+ (main==main))* ((main==main)+(main==main)) * ((main==main)+(main== main)))-(((main==main)+(main==main))*((main==main)+(main== main)))- (main==main)), putchar((((main==main)+(main==main))*((main==main) + (main==main)) * ((main==main)+(main==main)))+((main==main)+(main== main))),exit(main!=main),main==main){}}
That's undefined behaviour: exit() is implicitly declared by the call
as a function returning int, but the standard function exit() is
defined as returning void.
Jeremy.
Joona I Palaste <pa*****@cc.helsinki.fi> writes: Martin Dickopp <ex****************@zero-based.org> scribbled the following: Joona I Palaste <pa*****@cc.helsinki.fi> writes: Arthur J. O'Dwyer <aj*@nospam.andrew.cmu.edu> scribbled the following: On Mon, 10 May 2004, Yakov Lerner wrote: > b_*********@hotmail.com (Prashanth Badabagni) wrote: > > Can anybody tell me how to print "hello,world" without using semicolon > Here is a variation: write C program to print ";" > without using semicolon, digits, double quote, and single quote. > Assume ascii.
ASCII is off-topic in comp.lang.c. I think you meant to say, "Do not assume ASCII."
#include <stdio.h> #include <stdlib.h> #define Z ((int)NULL) #define P(x) printf(#x #define L(x) #x #define S L(| |)[!Z] int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f (++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z &&P(%c%c%d\n),S,S,Z)&&f(++i,i)){}else if(--l==Z&&P(%c/\n),S )&&f(++i,i)){}else if(exit(Z),Z){}}int main(){if(f(Z,Z)){}}
No fair with preprocessor trickery! When preprocessed, that code will contain plenty of double quotes. If I'm allowed to assume ASCII, I can write a program to do it containing double quotes only in standard headers, even after preprocessing.
If I can assume ASCII, it's easy to do without using any preprocessor facilities at all:
int main(void) { if (putchar((((main==main)+(main==main))*((main== main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+ (main==main))* ((main==main)+(main==main)) * ((main==main)+(main== main)))-(((main==main)+(main==main))*((main==main)+(main== main)))- (main==main)), putchar((((main==main)+(main==main))*((main==main) + (main==main)) * ((main==main)+(main==main)))+((main==main)+(main== main))),exit(main!=main),main==main){}}
That's pretty clever. My original program to print "Hello, world" without using literal values was pretty much the same way, except it used a static variable and its negation to form 0 and 1, and then use those to form all other natural numbers. I dare you to write a "Hello, world" program in the way you are doing above. It won't require particularly ingenious thinking but it will be tedious to type out.
I tend to use computers for boring and tedious tasks. :-) Below is a
program which reads some text from standard input (until end-of-file
condition or an error is encountered) and writes to standard output a
C program in the spirit of the above (but without nice formatting).
#include <stdio.h>
int main (void)
{
int ch;
puts ("int main(void){if(");
while ((ch = getchar ()) != EOF)
{
puts ("putchar(");
if (ch == 0)
puts ("main!=main");
else
{
int parens = 0;
while (1)
{
if (ch & 1)
puts ("(main==main)");
if ((ch >>= 1) != 0)
{
puts ("+((main==main)+(main==main))*(");
++parens;
}
else
break;
}
while (parens-- > 0)
putchar (')');
}
puts ("),");
}
puts ("exit(main!=main),main==main){}}");
return 0;
}
Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes: Martin Dickopp wrote: int main(void) { if (putchar((((main==main)+(main==main))*((main== main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+ (main==main))* ((main==main)+(main==main)) * ((main==main)+(main== main)))-(((main==main)+(main==main))*((main==main)+(main== main)))- (main==main)), putchar((((main==main)+(main==main))*((main==main) + (main==main)) * ((main==main)+(main==main)))+((main==main)+(main== main))),exit(main!=main),main==main){}}
That's undefined behaviour: exit() is implicitly declared by the call as a function returning int, but the standard function exit() is defined as returning void.
Good catch. The only solution I can think of is to rely on the
"implicitly return 0 from main" behavior in C99.
Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
On Mon, 10 May 2004, Joona I Palaste wrote: Martin Dickopp <ex****************@zero-based.org> scribbled the following: If I can assume ASCII, it's easy to do without using any preprocessor facilities at all:
That's pretty clever. My original program to print "Hello, world" without using literal values was pretty much the same way, except it used a static variable and its negation to form 0 and 1, and then use those to form all other natural numbers. I dare you to write a "Hello, world" program in the way you are doing above. It won't require particularly ingenious thinking but it will be tedious to type out.
Let's hear it for program generators! (Yes, this was tweaked by
hand to get it nice and square. But the factoring of each ASCII value
and printing of all the 'main==main's was done by computer.)
-Arthur
int main(void){if(putchar(((((main==main)+(main==main) )*((main==main)+
(main==main)+(main==main)+(main==main)))*(((main== main)+(main==main)+(
main==main))*((main==main)+(main==main)+(main==mai n)))))&&putchar(((((
(main==main)+(main==main))*((main==main)+(main==ma in)+(main==main)))*(
(((main==main)+(main==main)+(main==main))*(((main= =main)+(main==main))
*((main==main)+(main==main)+(main==main))))-(main==main)))-(main==main
)))&&putchar(((((main==main)+(main==main)+(main==m ain))*((main==main)+
(main==main)+(main==main)))*(((main==main)+(main== main)+(main==main))*
((main==main)+(main==main)+(main==main)+(main==mai n)))))&&putchar(((((
main==main)+(main==main)+(main==main))*((main==mai n)+(main==main)+!!!(
main!=main)))*(((main==main)+(main==main)+(main==m ain))*((main==main)+
(main==main)+(main==main)+(main==main)))))&&putcha r((((main==main)+!!!
(main!=main)+(main==main))*((((main==main)+(main== main))*(((!!!(main!=
main)+(main==main)+(main==main)+(main==main))*((ma in==main)+!!!(main!=
main)+(main==main)+(main==main)+(main==main)))-(main==main)))-!(main!=
main))))&&putchar((((main==main)+(main==main)+(mai n==main)+(main==main
))*((((main==main)+(main==main)+(main==main))*((ma in==main)+!!!(main!=
main)+(main==main)+(main==main)))-(main==main))))&&putchar(((!!(main==
main)+(main==main)+(main==main)+(main==main))*(((m ain==main)+!!(main==
main))*((main==main)+(main==main)+(main==main)+!!! !!(main!=main)))))&&
putchar((((((main==main)+(main==main))*((main==mai n)+(main==main)+!!!!
(main==main)+(main==main)))-(main==main))*((((main==main)+(main==main)
+(main==main))*(((main==main)+(main==main))*((main ==main)+(main==main)
+(main==main))))-(main==main))))&&putchar((((main==main)+(main==mai n)+
(main==main))*((((main==main)+(main==main))*((((ma in==main)+!!!(main!=
main)+(main==main)+(main==main))*((main==main)+(ma in==main)+!!!(main!=
main)+(main==main)+(main==main)))-(main==main)))-(main==main))))&&!!!!
putchar(((((main==main)+(main==main))*((main==main )+(main==main)+(main
==main)))*((((main==main)+(main==main)+(main==main )+(main==main))*(!!(
main==main)+(main==main)+(main==main)+(main==main) +(main==main)))-!!!(
main!=main))))&&putchar(((((main==main)+(main==mai n)+(main==main))*(!!
(main==main)+(main==main)+(main==main)))*(((main== main)+(main==main)+(
main==main))*((main==main)+(main==main)+(main==mai n)+!(main!=main)))))
&&putchar(((((main==main)+(main==main))*((main==ma in)+(main==main)+!!(
main==main)+(main==main)+(main==main)))*(((main==m ain)+(main==main))*(
(main==main)+(main==main)+(main==main)+(main==main )+(main==main)))))&&
putchar((((main==main)+(main==main)+(main==main))* ((((main==main)+!!!(
main!=main)+(main==main))*((main==main)+(main==mai n)+(main==main)+!!!(
main!=main)))-(main==main))))&&putchar((((main==main)+(main==mai n))*((
main==main)+(main==main)+(main==main)+(main==main) +(main==main))))){}}
Martin Dickopp wrote: Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
Martin Dickopp wrote: int main(void) { if (putchar((((main==main)+(main==main))*((main== main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+ (main==main))* ((main==main)+(main==main)) * ((main==main)+(main== main)))-(((main==main)+(main==main))*((main==main)+(main== main)))- (main==main)), putchar((((main==main)+(main==main))*((main==main) + (main==main)) * ((main==main)+(main==main)))+((main==main)+(main== main))),exit(main!=main),main==main){}}
That's undefined behaviour: exit() is implicitly declared by the call as a function returning int, but the standard function exit() is defined as returning void.
Good catch. The only solution I can think of is to rely on the "implicitly return 0 from main" behavior in C99.
If you use C99, though, you lose implicit declarations altogether, so
you need a declaration for putchar(), with a semicolon.
Jeremy.
Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes: Martin Dickopp wrote: Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
Martin Dickopp wrote: int main(void) { if (putchar((((main==main)+(main==main))*((main== main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+ (main==main))* ((main==main)+(main==main)) * ((main==main)+(main== main)))-(((main==main)+(main==main))*((main==main)+(main== main)))- (main==main)), putchar((((main==main)+(main==main))*((main==main) + (main==main)) * ((main==main)+(main==main)))+((main==main)+(main== main))),exit(main!=main),main==main){}}
That's undefined behaviour: exit() is implicitly declared by the call as a function returning int, but the standard function exit() is defined as returning void.
Good catch. The only solution I can think of is to rely on the "implicitly return 0 from main" behavior in C99.
If you use C99, though, you lose implicit declarations altogether, so you need a declaration for putchar(), with a semicolon.
Okay, I give up. :) There's no solution.
Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
"Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote in message news:<Pi**********************************@unix40. andrew.cmu.edu>... On Mon, 10 May 2004, Yakov Lerner wrote: b_*********@hotmail.com (Prashanth Badabagni) wrote: Can anybody tell me how to print "hello,world" without using semicolon Here is a variation: write C program to print ";" without using semicolon, digits, double quote, and single quote. Assume ascii.
ASCII is off-topic in comp.lang.c. I think you meant to say, "Do not assume ASCII."
#include <stdio.h> #include <stdlib.h> #define Z ((int)NULL) #define P(x) printf(#x #define L(x) #x #define S L(| |)[!Z] int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f (++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z
The \ in \n is not at the end of a line, not part of a character or
string literal, not part of a universal character, not part of an
include header, and does not constitute a punctuator or other
preprocessor token.
I know gcc does not issue a diagnostic, but unless I'm missing
something, it's a syntax error.
&&P(%c%c%d\n),S,S,Z)&&f(++i,i)){}else if(--l==Z&&P(%c/\n),S )&&f(++i,i)){}else if(exit(Z),Z){}}int main(){if(f(Z,Z)){}}
--
Peter
Jeremy Yallop wrote: Martin Dickopp wrote: int main(void) { if (putchar((((main==main)+(main==main))*((main== main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+ (main==main))* ((main==main)+(main==main)) * ((main==main)+(main== main)))-(((main==main)+(main==main))*((main==main)+(main== main)))- (main==main)), putchar((((main==main)+(main==main))*((main==main) + (main==main)) * ((main==main)+(main==main)))+((main==main)+(main== main))),exit(main!=main),main==main){}}
That's undefined behaviour: exit() is implicitly declared by the call as a function returning int, but the standard function exit() is defined as returning void.
Nope. exit is defined as never returning, so there is no
behaviour to become undefined.
--
"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - Bush.
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
CBFalconer <cb********@yahoo.com> writes: Jeremy Yallop wrote: That's undefined behaviour: exit() is implicitly declared by the call as a function returning int, but the standard function exit() is defined as returning void.
Nope. exit is defined as never returning, so there is no behaviour to become undefined.
Nonsense. You are wrong for the same reason that anyone who
makes the same claim about main() is wrong.
--
"What is appropriate for the master is not appropriate for the novice.
You must understand the Tao before transcending structure."
--The Tao of Programming
On Tue, 11 May 2004, CBFalconer wrote: Jeremy Yallop wrote: Martin Dickopp wrote: int main(void) { if (putchar((((main==main)+(main==main))*((main== main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+ (main==main))* ((main==main)+(main==main)) * ((main==main)+(main== main)))-(((main==main)+(main==main))*((main==main)+(main== main)))- (main==main)), putchar((((main==main)+(main==main))*((main==main) + (main==main)) * ((main==main)+(main==main)))+((main==main)+(main== main))),exit(main!=main),main==main){}}
That's undefined behaviour: exit() is implicitly declared by the call as a function returning int, but the standard function exit() is defined as returning void.
Nope. exit is defined as never returning, so there is no behaviour to become undefined.
You should know better than that! One of the possible effects of
undefined behavior is the computer's actually coming backwards in
time to mess up the program before it even gets to the trouble spot...
Suppose 'exit' is defined with a calling convention such that
it expected to see one parameter on the stack, followed by a return
address which it will use to print a diagnostic message to the
user if 'errno' is set. Suppose further that to preserve register
real estate, 'int' values are returned by the caller's allocating
some (write-only) space on the stack prior to pushing its return
address and any arguments to the function. (Note that variadic
functions must be *really* perverse on this implementation!)
Now, we call 'exit' as if it is a regular function returning an
'int'. We push our return address, then a write-only buffer for
the return value, and then the argument 0. 'exit' tries to read our
buffer as if it were an address, and we get an exception. Ta-da!
HTH,
-Arthur
Ben Pfaff wrote: CBFalconer <cb********@yahoo.com> writes: Jeremy Yallop wrote: That's undefined behaviour: exit() is implicitly declared by the call as a function returning int, but the standard function exit() is defined as returning void.
Nope. exit is defined as never returning, so there is no behaviour to become undefined.
Nonsense. You are wrong for the same reason that anyone who makes the same claim about main() is wrong.
But main will return sooner or later, and its return value will be
used somehow. This does not apply to exit.
--
"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - Bush.
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
CBFalconer <cb********@yahoo.com> writes: Ben Pfaff wrote: CBFalconer <cb********@yahoo.com> writes: Jeremy Yallop wrote:
That's undefined behaviour: exit() is implicitly declared by the call as a function returning int, but the standard function exit() is defined as returning void.
Nope. exit is defined as never returning, so there is no behaviour to become undefined.
Nonsense. You are wrong for the same reason that anyone who makes the same claim about main() is wrong.
But main will return sooner or later, and its return value will be used somehow. This does not apply to exit.
Irrelevant. Read the standard. There is no difference between
the situations. Both instances are undefined.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
"Arthur J. O'Dwyer" wrote: On Tue, 11 May 2004, CBFalconer wrote: Jeremy Yallop wrote: Martin Dickopp wrote: > int main(void) { if (putchar((((main==main)+(main==main))*((main== > main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+ > (main==main))* ((main==main)+(main==main)) * ((main==main)+(main== > main)))-(((main==main)+(main==main))*((main==main)+(main== main)))- > (main==main)), putchar((((main==main)+(main==main))*((main==main) + > (main==main)) * ((main==main)+(main==main)))+((main==main)+(main== > main))),exit(main!=main),main==main){}}
That's undefined behaviour: exit() is implicitly declared by the call as a function returning int, but the standard function exit() is defined as returning void.
Nope. exit is defined as never returning, so there is no behaviour to become undefined.
You should know better than that! One of the possible effects of undefined behavior is the computer's actually coming backwards in time to mess up the program before it even gets to the trouble spot...
Suppose 'exit' is defined with a calling convention such that it expected to see one parameter on the stack, followed by a return address which it will use to print a diagnostic message to the user if 'errno' is set. Suppose further that to preserve register real estate, 'int' values are returned by the caller's allocating some (write-only) space on the stack prior to pushing its return address and any arguments to the function. (Note that variadic functions must be *really* perverse on this implementation!) Now, we call 'exit' as if it is a regular function returning an 'int'. We push our return address, then a write-only buffer for the return value, and then the argument 0. 'exit' tries to read our buffer as if it were an address, and we get an exception. Ta-da!
We can agree on don't do dat, and that this whole thread is silly
and totally without redeeming features, but ...
Why can't we just use K&R source, not needing any prototypes, and
which has never heard the word 'void'? The need to handle such
prevents your mechanism above, IMO. Since the system is using
implicit int it must be C90, not C99.
--
"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - Bush.
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes. ai***@acay.com.au (Peter Nilsson) wrote: "Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote in message #define P(x) printf(#x #define L(x) #x #define S L(| |)[!Z] int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f (++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z
The \ in \n is not at the end of a line, not part of a character or string literal, not part of a universal character, not part of an include header, and does not constitute a punctuator or other preprocessor token.
Macro processing, including # stringising macros, is done in translation
phase 4; escape sequences are translated in phase 5. AFAICT this is
enough to ensure that the above is legal (at least in this regard!),
since by the time the backslash is seen, it _is_ part of a string
literal.
Richard
"Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote: #include <stdio.h> #include <stdlib.h> #define Z ((int)NULL) #define P(x) printf(#x #define L(x) #x #define S L(| |)[!Z] int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f (++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z &&P(%c%c%d\n),S,S,Z)&&f(++i,i)){}else if(--l==Z&&P(%c/\n),S )&&f(++i,i)){}else if(exit(Z),Z){}}int main(){if(f(Z,Z)){}}
Alas, there is another, quite serious, bug in this program... it invokes
undefined behaviour! It calls f(++i,i) four times, each time modifying
the object i and accessing it for another purpose without an intervening
sequence point - that's a separator, not a comma operator! Fortunately,
this can easily be solved by changing all of these calls to f(++i,l).
Richard
On Mon, 10 May 2004 22:12:34 +0200,
Martin Dickopp <ex****************@zero-based.org> wrote
in Msg. <cu*************@zero-based.org> Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
Martin Dickopp wrote: int main(void) { if (putchar((((main==main)+(main==main))*((main== main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+ (main==main))* ((main==main)+(main==main)) * ((main==main)+(main== main)))-(((main==main)+(main==main))*((main==main)+(main== main)))- (main==main)), putchar((((main==main)+(main==main))*((main==main) + (main==main)) * ((main==main)+(main==main)))+((main==main)+(main== main))),exit(main!=main),main==main){}}
That's undefined behaviour: exit() is implicitly declared by the call as a function returning int, but the standard function exit() is defined as returning void.
Good catch. The only solution I can think of is to rely on the "implicitly return 0 from main" behavior in C99.
How about (int)exit() ?
--Daniel
--
"With me is nothing wrong! And with you?" (from r.a.m.p)
Daniel Haude <ha***@physnet.uni-hamburg.de> writes: On Mon, 10 May 2004 22:12:34 +0200, Martin Dickopp <ex****************@zero-based.org> wrote in Msg. <cu*************@zero-based.org> Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
Martin Dickopp wrote: int main(void) { if (putchar((((main==main)+(main==main))*((main== main)+(main==main)) * ((main==main)+(main==main)) * ((main==main)+ (main==main))* ((main==main)+(main==main)) * ((main==main)+(main== main)))-(((main==main)+(main==main))*((main==main)+(main== main)))- (main==main)), putchar((((main==main)+(main==main))*((main==main) + (main==main)) * ((main==main)+(main==main)))+((main==main)+(main== main))),exit(main!=main),main==main){}}
That's undefined behaviour: exit() is implicitly declared by the call as a function returning int, but the standard function exit() is defined as returning void.
Good catch. The only solution I can think of is to rely on the "implicitly return 0 from main" behavior in C99.
How about (int)exit() ?
That doesn't help, and wouldn't have any effect anyway, as `exit'
doesn't return. The problem is that the behavior becomes undefined as
soon as an undeclared (or "implictly declared") function returning
anything but `int' is /called/.
Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/ rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<40****************@news.individual.net>... ai***@acay.com.au (Peter Nilsson) wrote:
"Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote in message #define P(x) printf(#x #define L(x) #x #define S L(| |)[!Z] int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f (++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z
The \ in \n is not at the end of a line, not part of a character or string literal, not part of a universal character, not part of an include header, and does not constitute a punctuator or other preprocessor token.
Macro processing, including # stringising macros, is done in translation phase 4; escape sequences are translated in phase 5.
But conversion to preprocessing tokens occurs in phase 3, by which
time an isolated backslash character like the one above is _not_ a
preprocessor token.
--
Peter ai***@acay.com.au (Peter Nilsson) writes: rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<40****************@news.individual.net>... ai***@acay.com.au (Peter Nilsson) wrote:
> "Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote in message > > #define P(x) printf(#x > > #define L(x) #x > > #define S L(| |)[!Z] > > int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f > > (++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z > > The \ in \n is not at the end of a line, not part of a character or > string literal, not part of a universal character, not part of an > include header, and does not constitute a punctuator or other > preprocessor token.
Macro processing, including # stringising macros, is done in translation phase 4; escape sequences are translated in phase 5.
But conversion to preprocessing tokens occurs in phase 3, by which time an isolated backslash character like the one above is _not_ a preprocessor token.
Why not? 6.4#3:
| [...] A preprocessing token is the minimal lexical element of the
| language in translation phases 3 through 6. The categories of
| preprocessing tokens are: header names, identifiers, preprocessing
| numbers, character constants, string literals, punctuators, and single
| non-white-space characters that do not lexically match the other
| preprocessing token categories. [...]
A single backslash character seems to fit into the last category.
Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Martin Dickopp <ex****************@zero-based.org> wrote in message news:<cu*************@zero-based.org>... ai***@acay.com.au (Peter Nilsson) writes:
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote in message news:<40****************@news.individual.net>... ai***@acay.com.au (Peter Nilsson) wrote:
> "Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote in message > > #define P(x) printf(#x > > #define L(x) #x > > #define S L(| |)[!Z] > > int f(int l,int i){if((i=l,!Z)&&l==Z&&P(%c%c%d\n),S,S,Z)&&f > > (++i,i)){}else if(--l==Z&&P(\n))&&f(++i,i)){}else if(--l==Z > > The \ in \n is not at the end of a line, not part of a character or > string literal, not part of a universal character, not part of an > include header, and does not constitute a punctuator or other > preprocessor token.
Macro processing, including # stringising macros, is done in translation phase 4; escape sequences are translated in phase 5.
But conversion to preprocessing tokens occurs in phase 3, by which time an isolated backslash character like the one above is _not_ a preprocessor token.
Why not? 6.4#3:
| [...] A preprocessing token is the minimal lexical element of the | language in translation phases 3 through 6. The categories of | preprocessing tokens are: header names, identifiers, preprocessing | numbers, character constants, string literals, punctuators, and single | non-white-space characters that do not lexically match the other | preprocessing token categories. [...]
A single backslash character seems to fit into the last category.
Yup, my (very) bad.
--
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ankursinha |
last post by:
Hi,
Is it possible to write a C program that prints "Hello World" on screen without
having a single semi-colon in the entire program?
The extra constraint here is that u r not allowed to use...
|
by: Spidey |
last post by:
for(;0;)
printf("hello");
even the condition s wrong i get a hello printed on the screen
y s this happening
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| | |