473,805 Members | 2,154 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
17 2350
Alan Balmer <al******@att.n et> wrote in message news:<mk******* *************** **********@4ax. com>...
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.


The behaviour is effectively undefined. Once you call system with a
non-null string, you potentially lose the guarantee of conforming
behaviour (assuming system even returns).

--
Peter
Nov 14 '05 #11
In <Pi************ *************** ********@unix41 .andrew.cmu.edu > "Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> writes:
In C89/C90/C95, falling off the end of 'main' returns
an implementation-defined value to the system.


Nope, the value is *undefined*.

If the main function executes a return that specifies no value,
the termination status returned to the host environment is undefined.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #12
In <63************ **************@ posting.google. com> ai***@acay.com. au (Peter Nilsson) writes:
The behaviour is effectively undefined.


The behaviour is mereley defined by another document.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #13
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote ...
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);'.


A reference to a section in the standards to substantiate
your claim(s) would be appreciated here.

ISO Section 5.1.2.2.3#1 starts as follows:
"If the return type of the main function is a type compatible
with int,..." [snipped for brevity]

Further on, ISO Section 6.8.6.4#1 says:
"A return statement with an expression shall not appear in a
function whose return type is void. A return statement without
an expression shall only appear in a function whose return
type is void."

CMIIW, but my limited intellect says that this implies that
'main' expects a return statement [or exit(...) for the pedants].
--
Devarshi Chatterjee.
Nov 14 '05 #14
Devarshi Chatterjee wrote:
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote ...
In C99, falling off the end of 'main' is exactly equivalent
to returning 0 via 'return 0;' or 'exit(0);'.


A reference to a section in the standards to substantiate
your claim(s) would be appreciated here.

ISO Section 5.1.2.2.3#1 starts as follows:
"If the return type of the main function is a type compatible
with int,..." [snipped for brevity]


... 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; reaching the } that terminates
the main function returns a value of 0.
Nov 14 '05 #15
In <7d************ **************@ posting.google. com> so*******@blueb ottle.com (Devarshi Chatterjee) writes:
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote ...
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);'.
A reference to a section in the standards to substantiate
your claim(s) would be appreciated here.

ISO Section 5.1.2.2.3#1 starts as follows:
"If the return type of the main function is a type compatible
with int,..." [snipped for brevity]


You should have read the text you've snipped, because this is what it
says:

... 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;10) reaching the } that
^^^^^^^^^^^^^^^ ^^^^
terminates the main function returns a value of 0.
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^
Further on, ISO Section 6.8.6.4#1 says:
"A return statement with an expression shall not appear in a
function whose return type is void. A return statement without
an expression shall only appear in a function whose return
type is void."

CMIIW, but my limited intellect says that this implies that
'main' expects a return statement [or exit(...) for the pedants].


Your intellect is too limited: nothing in 6.8.6.4#1 forbids a function
returning something to terminate without a return statement. And
5.1.2.2.3#1 *explicitly* documents what happens when a main defined as
returning int terminates without a return statement. If you're
curious about what happens in other such cases, the answer is provided
by 6.9.1#12:

12 If the } that terminates a function is reached, and the value
of the function call is used by the caller, the behavior is
undefined.

Therefore, the following is a strictly conforming C99 program, with a
well defined termination status. In C89, the termination status would be
undefined.

#include <stdio.h>

int foo(void) { printf("hello world\n"); }

int main() { foo(); }

I would expect a good compiler to emit a warning for each function
defined in this program, but the standard requires no diagnostic.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #16
"Dan Pop" <Da*****@cern.c h> wrote:
If you're curious about what happens in other such cases, the answer
is provided by 6.9.1#12:

12 If the } that terminates a function is reached, and the
value of the function call is used by the caller, the
behavior is undefined.

Therefore, the following is a strictly conforming C99 program, with
a well defined termination status. In C89, the termination status
would be undefined.
My copy of C89 has equivalent wording in 3.6.6.4#4:

If a return statement without an expression is executed,
and the value of the function call is used by the caller,
the behavior is undefined. Reaching the } that terminates
a function is equivalent to executing a return statement
without an expression.

Following this logic, since the value of the function call to main is used
by its caller, the behaviour is undefined. I don't think there is such a
thing as an "undefined termination status". In this case, the program has
"undefined behaviour".
#include <stdio.h>

int foo(void) { printf("hello world\n"); }

int main() { foo(); }

I would expect a good compiler to emit a warning for each function
defined in this program, but the standard requires no diagnostic.


Agreed.

--
Simon.
Nov 14 '05 #17
In <dc************ *************** ***@news.terane ws.com> "Ralmin" <ne**@ralminNOS PAM.cc> writes:
"Dan Pop" <Da*****@cern.c h> wrote:
If you're curious about what happens in other such cases, the answer
is provided by 6.9.1#12:

12 If the } that terminates a function is reached, and the
value of the function call is used by the caller, the
behavior is undefined.

Therefore, the following is a strictly conforming C99 program, with
a well defined termination status. In C89, the termination status
would be undefined.


My copy of C89 has equivalent wording in 3.6.6.4#4:

If a return statement without an expression is executed,
and the value of the function call is used by the caller,
the behavior is undefined. Reaching the } that terminates
a function is equivalent to executing a return statement
without an expression.

Following this logic, since the value of the function call to main is used
by its caller, the behaviour is undefined. I don't think there is such a
thing as an "undefined termination status". In this case, the program has
"undefined behaviour".


Why didn't you bother checking your copy of C89? You'd have learned that
there is such thing as "undefined termination status" and, therefore, the
program doesn't invoke undefined behaviour:

"Program termination"

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. If the main function executes a return that
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^
specifies no value, the termination status returned to the host
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^
environment is undefined.
^^^^^^^^^^^^^^^ ^^^^^^^^^^

According to your own quote, falling off the end of main is the equivalent
to executing a return with no value.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #18

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

Similar topics

0
1367
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
3459
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
2191
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
5588
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
2017
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
2294
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
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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
10613
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
10363
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
10107
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
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
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.