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

Home Posts Topics Members FAQ

Without semicolons

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.
Nov 14 '05
27 2016

On Mon, 10 May 2004, Jeremy Yallop wrote:

It might appear that a (non-definition) declaration is required for at
least one of two mutually recursive functions, but that's not the
case:

void one()
{
if (((void (*)())two)(), 0) { }
I don't think this does what you think it does. I *think* (pretty
strongly, but not entirely positive) that it implicitly declares
'two' as an 'int', and then tries to cast that 'int' to 'void(*)()'.
What you really meant to do was declare 'two' as a 'void(*)()', and
I think you might not be able to do that.
So, expert opinions needed on this, and also on this "solution":

void declare_voidCpD CD(void (*x)()) {}

void one()
{
if (declare_voidCp DCD(two), two(), 0) {}
}

Does the passing of 'two' to a function expecting a given type
implicitly declare 'two' with that type?

I'm pretty sure that it can be done, although I welcome
counterexamples . I'm sorry that you thought the problem was stupid; I
thought it was considerably more interesting than the usual "without
using a semicolon" sort of questions that come up fairly frequently,
and (if solved) it has the additional advantage of making it
unnecessary to ever have to think of answers to those questions again.
:-D
I think that a program I'm working on now will be able to solve the
problem (and many others) when finished,


This program isn't called the Analytical Engine, by any chance? ;)

-Arthur
Nov 14 '05 #11
Jeremy Yallop wrote:
Jeremy Yallop wrote:
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.


It might appear that a (non-definition) declaration is required for at
least one of two mutually recursive functions, but that's not the
case:


....in C89. Implicit function declarations were removed for C99.
(Besides, I'm pretty sure that even in C89 you couldn't cast any
undeclared identifier and then call it as a function; it appears
that it may be solvable in C89 by other means, though. Wrappers
are your friends here, if you really want to spend as many hours
of your life as this will indubitably take to accomplish without
any gaps on such a project.)

--
++acr@,ka"
Nov 14 '05 #12
Chris McDonald wrote:
Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> writes:
Chris McDonald wrote:
.... snip ...

Yes sir, I'll get on to writing this program straight away.
I'm not interested in the DMS Software Reengineering Toolkit,
either.

If you were to search the archives (or lurk for a while) in
order to establish some context, you might be less inclined to
post such rude (and absurd) responses.


I read this newsgroup everyday. What possible context is there?


There is a poster, who shall remain nameless, who pops up
periodically to flog the aforementioned Toolkit as the solution to
various problems. He never has any other comments or knowledge to
offer. That was a joke son, which you failed to recognize and
converted into a flame.

--
"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.

Nov 14 '05 #13
Arthur J. O'Dwyer wrote:

On Mon, 10 May 2004, Jeremy Yallop wrote:

It might appear that a (non-definition) declaration is required for at
least one of two mutually recursive functions, but that's not the
case:

void one()
{
if (((void (*)())two)(), 0) { }
I don't think this does what you think it does. I *think* (pretty
strongly, but not entirely positive) that it implicitly declares
'two' as an 'int', and then tries to cast that 'int' to 'void(*)()'.


It's worse than that: it's just a plain error. "Implicit int" refers
to variable declarations without a type specifier, such as

static x;

As Sam Dennis points out, you can't use an undeclared identifier in
this context.
What you really meant to do was declare 'two' as a 'void(*)()', and
I think you might not be able to do that.
So, expert opinions needed on this, and also on this "solution":

void declare_voidCpD CD(void (*x)()) {}

void one()
{
if (declare_voidCp DCD(two), two(), 0) {}
}

Does the passing of 'two' to a function expecting a given type
implicitly declare 'two' with that type?


Unfortunately not: any undeclared identifier used as a function
designator is implicitly declared as returning int. I've realised
since I wrote the post you're replying to that implicit declaration
won't work at all here, since it can only be used for functions
returning int.
I think that a program I'm working on now will be able to solve the
problem (and many others) when finished,


This program isn't called the Analytical Engine, by any chance? ;)


Heh. That's not a bad name, actually. It's intended to be used for
general syntactic analysis (and transformations ) of C source code;
basically a fancy parser with a bunch of hooks. I'm happy to say,
though, that its completion isn't dependent on the support of the
British government.

Jeremy.
Nov 14 '05 #14
Jeremy Yallop wrote:
Chris McDonald wrote:
Jeremy Yallop wrote:
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.


Yes sir, I'll get on to writing this program straight away. I'm
not interested in the DMS Software Reengineering Toolkit, either.


If you were to search the archives (or lurk for a while) in order
to establish some context, you might be less inclined to post such
rude (and absurd) responses.


"Yes sir, I'll get on to writing this program straight away." is
rude?!? You, my friend, seem to lack perspective.

Nov 14 '05 #15
Jeremy Yallop wrote:
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.


The answer has been posted here many times.
Please search the newsgroups for "without" and "semicolon" .

--
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.l earn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Nov 14 '05 #16
Jeremy Yallop wrote:
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.


Replace all semicolons with NOT_A_SEMICOLON between some white space
and compile with the appropriate-something-like -DNOT_A_SIMICOLO N=;
flag :-)

Or is this not funny?

Case

Nov 14 '05 #17
Thomas Matthews <Th************ *************@s bcglobal.net> writes:
Jeremy Yallop wrote:
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.


The answer has been posted here many times.


Huh? I seriously doubt that. :)

Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #18
Case <no@no.no> writes:
Jeremy Yallop wrote:
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.


Replace all semicolons with NOT_A_SEMICOLON between some white space
and compile with the appropriate-something-like -DNOT_A_SIMICOLO N=;
flag :-)


A compiler invoked with such a flag is *not* a conforming C
implementation.

Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #19

On Tue, 11 May 2004, Jeremy Yallop wrote:

Arthur J. O'Dwyer wrote:
On Mon, 10 May 2004, Jeremy Yallop wrote:

if (((void (*)())two)(), 0) { }
I don't think this does what you think it does. I *think* (pretty
strongly, but not entirely positive) that it implicitly declares
'two' as an 'int', and then tries to cast that 'int' to 'void(*)()'.


It's worse than that: it's just a plain error.

[snip] As Sam Dennis points out, you can't use an undeclared identifier in
this context.


<slaps my forehead> Right. Well, anyway...
void declare_voidCpD CD(void (*x)()) {}

void one()
{
if (declare_voidCp DCD(two), two(), 0) {}
}

Does the passing of 'two' to a function expecting a given type
implicitly declare 'two' with that type?


Unfortunately not: any undeclared identifier used as a function
designator is implicitly declared as returning int.


<slaps your forehead> ;) No, I wasn't thinking again. This code
suffers from the same problem Sam Dennis showed with your code ---
'two' is undeclared in the first place it appears. That's a
syntax error. Still, we could write

if (0, two()) {}
if (((void(*)())tw o)(), 0) {}

and I believe the code would be strictly conforming. Or even:

if (sizeof two(), ((void(*)())two )(), 0) {}

Both of these implicitly declare 'two' as a function (of whatever
type), and then we cast the value of 'two' to the correct function
pointer type before we actually call it.

But the original problem, mutual recursion, is much easier
anyway:

void one(void (*two)()) {
if (two(one), 0) {}
}

void two(void (*one)()) {
if (one(two), 0) {}
}

int main(void) {
if (one(two), 0) {}
}

We were just trying to over-complicate things. :)
-Arthur
Nov 14 '05 #20

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

Similar topics

1
2155
by: Mage | last post by:
Hello, I amafraid of I will stop using semicolons in other languages after one or two months of python. However I see that python simply ignores the semicolons atd the end of the lines. What's your advice? I don't want to write full-of-typo php scripts but I see the logic of the python syntax too. Mage
1
1806
by: jjbutera | last post by:
How do I escape these? The backslash doesn't seem to be working.
4
2954
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400, like DOS, uses memory-mapped display, two bytes per character (one char byte and one attribute byte). We can get the screen offset allright, and I've written a javascript which does the math to convert the offset into row/col (i.e. left, top)...
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...
17
2348
by: subnet | last post by:
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
4
1412
by: Waxhead | last post by:
Hi folks, First of all I'm new to newsgroups so please don't kill me in case I'm breaking any rules , but if you really have to make it quick and painfull ;) What is actually propper hehaviour of Snippet 1 ? as I understand it the result should be the same as snippet 2. (but it isn't at least with my compiler). I expect snippet 1 to work like this: if then for and function() else just function() or perhaps a bit clearer:
3
1555
by: Stefan Mueller | last post by:
I've a web page with several input boxes. After the user clicks 'submit' I insert these data into my MySQL database. This worked for several months perfect. But today a user entered the street name Route d'Yverdon 59 unfortunately the data has not been inserted into my MySQL database because of the apostroph (') in the name of the street. I've no idea how to deal with this problem.
12
2543
by: feel | last post by:
Hi,All I am sure it's an old question. But I just find a interesting design about this: Polymorphism without virtual function in a C++ class. My solution is for some special case, trust me, very special. 1 single root class tree 2 the leaf(lowest level) classes are sealed which means we should not inherite class from them. 3 PImpl idiom. There is only one data mumber in root class and there is no any other data mumber in child class and...
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...
1
10200
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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...
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
6800
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.