473,796 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programs without semicolon

I'm not a C expert, but I've seen this topic discussed in the
newsgroup several times. What's the deal with writing such programs?
Why are they considered so interesting?

Thanks
Nov 14 '05 #1
17 2348
subnet <su****@katamai l.com> scribbled the following:
I'm not a C expert, but I've seen this topic discussed in the
newsgroup several times. What's the deal with writing such programs?
Why are they considered so interesting?


Beats me. Maybe some professor is handing out such assignments like
they're going out of fashion, which I certainly hope they are.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"'It can be easily shown that' means 'I saw a proof of this once (which I didn't
understand) which I can no longer remember'."
- A maths teacher
Nov 14 '05 #2
On Tue, 11 May 2004, subnet wrote:
I'm not a C expert, but I've seen this topic discussed in the
newsgroup several times. What's the deal with writing such programs?
Why are they considered so interesting?


It is hard to do without getting creative. The idea is that you really
have to know the language and have a bit of creativity to be able to write
such a program.

The other thought is that if you can write such a program you 1) know a
lot about the language and 2) you can recall the appropriate information.

For example, everyone with a degree in Computer Science learned about
recursion. If I pose a challenge that requires recursion to solve it not
everyone will be able to figure it out even though they have all had
training on recursion. Having training is one thing. Using it effectively
is what employers are really looking for.

The truth of the matter is that many people are just good at using a
search engine or memorizing questions that people like to use in
interviews.

One other aspect of these questions is that once I know what the answer is
I can impress my friends by asking them the same question and watch them
struggle with finding the answer.

The specific challenge of writing a program that has no semicolons comes
from the fact that everyone is taught that:

int main(void)
{
return 0;
}

is a minimal program. You start with this and build from here. If this
really is the simpliest program and there is already one semicolon in it,
how do you get rid of the semicolon?

int main(void)
{
return 0
}

This will not compile. You actually have to make the code more complex to
be able to remove the semicolon.

--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@ whitehouse.gov
Nov 14 '05 #3
In <Pi************ *************** ****@drj.pf> da*****@NOMORES PAMcs.utoronto. ca.com (Darrell Grainger) writes:
On Tue, 11 May 2004, subnet wrote:
I'm not a C expert, but I've seen this topic discussed in the
newsgroup several times. What's the deal with writing such programs?
Why are they considered so interesting?


It is hard to do without getting creative. The idea is that you really
have to know the language and have a bit of creativity to be able to write
such a program.


Not really. You know from start that your main function can't contain
any statement or declaration, except the ones of its two parameters.
There is nothing useful you can do in the declaration of argc, so your
only remaining hope is argv. After this trivial analysis, the solution
becomes obvious to anyone familiar with C99.

The C89 reasoning is a bit more complex, but still no big deal:
The only statement that doesn't require a terminating semicolon is the
empty block statement. So you can make your function call in the
controlling expression of an if or while statement that conditionally
executes an empty block statement. The while statement even allows
programming loops.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #4
> int main(void)
{
return 0
}

This will not compile. You actually have to make the code more complex to
be able to remove the semicolon.


No, you will have to make it simpler:

int main(){}

compiles fine on GCC.
Nov 14 '05 #5
Pl**********@ly cos.co.uk (PlasmaDragon) wrote:
int main(void)
{
return 0
}

This will not compile. You actually have to make the code more complex to
be able to remove the semicolon.


No, you will have to make it simpler:

int main(){}

compiles fine on GCC.


It compiles fine, but it returns garbage.

Richard
Nov 14 '05 #6
In <40************ ****@news.indiv idual.net> rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
Pl**********@l ycos.co.uk (PlasmaDragon) wrote:
> int main(void)
> {
> return 0
> }
>
> This will not compile. You actually have to make the code more complex to
> be able to remove the semicolon.


No, you will have to make it simpler:

int main(){}

compiles fine on GCC.


It compiles fine, but it returns garbage.


Who says it shouldn't return garbage?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #7
> It compiles fine, but it returns garbage.

Richard


Returns fine for me. Here's a test program:

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

int main()
{
int x;
x=system("nosem icolon");
printf("%d",x);
printf("\n\n");

system("PAUSE") ;
}

Where "nosemicolo n" is the name of your program that doesn't have a
semicolon. I always get the output 0.
Nov 14 '05 #8
On 12 May 2004 10:41:04 -0700, Pl**********@ly cos.co.uk (PlasmaDragon)
wrote:
It compiles fine, but it returns garbage.

Richard


Returns fine for me. Here's a test program:

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

int main()
{
int x;
x=system("nosem icolon");
printf("%d",x);
printf("\n\n");

system("PAUSE") ;
}

Where "nosemicolo n" is the name of your program that doesn't have a
semicolon. I always get the output 0.


What you're printing is the return value of system, which is
implementation-defined and may or may not reflect the return value of
nosemicolon.

BTW, why

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

rather than

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

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 14 '05 #9

On Wed, 12 May 2004, PlasmaDragon wrote:
[please don't snip attributions, PlasmaDragon]
It compiles fine, but it returns garbage.

Richard


Returns fine for me. Here's a test program:

<snip> I always get the output 0.


Really? Prove it!

Test programs prove nothing, by definition. Besides,
you're arguing about a stupid quirk that's easily figured
out by consulting the Standards or a relevant FAQ.

In C89/C90/C95, falling off the end of 'main' returns
an implementation-defined value to the system.
In C99, falling off the end of 'main' is exactly equivalent
to returning 0 via 'return 0;' or 'exit(0);'.

This appears to be one of those cases where the C89 bigots
and the C99 bigots are simply butting heads for the heck of
it. If you guys would just say, "This answer refers to the
standard of 1989" and "This answer refers to the standard of
1999," threads like this one simply wouldn't happen.

-Arthur
Nov 14 '05 #10

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

Similar topics

0
1366
by: Nikola Milutinovic | last post by:
Hi all. I'm not subscribed to the list, so all replies to me mail directly. I ran into a small problem, for which we have found a workaround. I was compiling PostgreSQL v7.4.1 and it's PL/Python module. Compilation failed on lines which had this: typedef struct PLyPlanObject { PyObject_HEAD; ... } PLyPlanObject;
12
3457
by: jrefactors | last post by:
If the C programs have UNIX system calls such as fork(), alarm(), etc.., we should call it UNIX programs, not traditional C programs? We couldn't compile the programs with system calls using VC++ compiler. I need to compile it under UNIX platform. correct? any other alternatives?? Please advise. Thanks!!
9
2189
by: Jukka K. Korpela | last post by:
I noticed that Internet Explorer (6.0, on Win XP SP 2, all fixes installed) incorrectly renders e.g. &harr &euro &Omega literally and not as characters denoted by the entities, but if a semicolon is appended to each of the entity references, they work. I'm pretty sure that previous versions of IE rendered them by the specifications. I first thought this has something to do with XML (i.e. maybe IE pretends to play a little bit of XML...
33
5583
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 if,while,switch etc. So far,i figured this could be done by insertint the printf statement in main as shown: int main(int argc=printf("Hello world")
27
2016
by: Jeremy Yallop | last post by:
Write a program that takes a C program in source form as input and prints the source code for a program with equivalent behaviour, but without semicolons, on standard output. Please note that I'm not interested in the DMS Software Reengineering Toolkit. Jeremy.
2
2545
by: muzammil azmi | last post by:
how can i compile/run a program without using semicolonin the program
3
7146
by: Peter Michaux | last post by:
Hi, These first three links say that when reading document.cookie the name-value pairs are separated by semicolons and they show examples like "name=value;expires=date" where there is clearly only a semicolon separator. <http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-1006298752-h2> <http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-8747038> <http://developer.mozilla.org/en/docs/DOM:document.cookie#Parameters>
2
2293
by: kolla | last post by:
how to write a c programme to print a semicolon without writing using a semicolon in the main program
1
1345
by: cybersuv | last post by:
Is There Any Way To Print "hallow" In C Without Using A Single Semicolon ... Please Help Me If Anyone Can...
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10465
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10242
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.