By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,979 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,979 IT Pros & Developers. It's quick & easy.

Without semicolons

P: n/a
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 #1
Share this Question
Share on Google+
27 Replies


P: n/a
int main(int x, char *t[]){if(puts(t[1])){}}

compile to file 'a' and run this in your command line

a "the source goes here"
Nov 14 '05 #2

P: n/a
Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
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.

Chris.
Nov 14 '05 #3

P: n/a
Chris McDonald wrote:
Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
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.

Jeremy.
Nov 14 '05 #4

P: n/a
Martin Johansen wrote:
int main(int x, char *t[]){if(puts(t[1])){}}

compile to file 'a' and run this in your command line

a "the source goes here"


I have no idea why you think this is a solution.

Jeremy.
Nov 14 '05 #5

P: n/a
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.


There is one really serious problem with that, other than string
literals and character constants (and being a stupid idea in the
first place): declarations are terminated with a semi-colon.

--
++acr@,ka"
Nov 14 '05 #6

P: n/a
Sam Dennis 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.


There is one really serious problem with that, other than string
literals and character constants (and being a stupid idea in the
first place): declarations are terminated with a semi-colon.


String literals and character constants are not a problem if you don't
mind restricting yourself to a particular character set. Declarations
are admittedly rather difficult to handle, but by no means impossible.
Here are a couple of clues:

int foo()
{
int x = 3;
float y = 2.0;
...
return something;
}

can be transformed to

void foo_helper(int x, float y, int *rv)
{
...
if (*rv = something) { }
}

void foo(int *rv)
{
if (foo_helper(3, 2.0, rv)) { }
}

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) { }
}

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

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.

I think that a program I'm working on now will be able to solve the
problem (and many others) when finished, by the way, but it's not
written in C and it won't be ready for a couple of months at least.

Jeremy.
Nov 14 '05 #7

P: n/a
Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
Chris McDonald wrote:
Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
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.

I read this newsgroup everyday.
What possible context is there?
Please explain how the directive to write such a program should be obeyed
by our readers.

The initial request is the absurb matter.
Nov 14 '05 #8

P: n/a
Chris McDonald wrote:
I read this newsgroup everyday.
What possible context is there?
Please explain how the directive to write such a program should be obeyed
by our readers.


Could we talk about C, instead, please?

Jeremy.
Nov 14 '05 #9

P: n/a
Chris McDonald wrote:
I read this newsgroup everyday.
What possible context is there?
Please explain how the directive to write such a program should be obeyed
by our readers.


Could we talk about C instead, please?

Jeremy.
Nov 14 '05 #10

P: n/a

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_voidCpDCD(void (*x)()) {}

void one()
{
if (declare_voidCpDCD(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

P: n/a
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

P: n/a
Chris McDonald wrote:
Jeremy Yallop <je****@jdyallop.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

P: n/a
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_voidCpDCD(void (*x)()) {}

void one()
{
if (declare_voidCpDCD(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

P: n/a
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

P: n/a
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.learn.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

P: n/a
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_SIMICOLON=;
flag :-)

Or is this not funny?

Case

Nov 14 '05 #17

P: n/a
Thomas Matthews <Th*************************@sbcglobal.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

P: n/a
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_SIMICOLON=;
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

P: n/a

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_voidCpDCD(void (*x)()) {}

void one()
{
if (declare_voidCpDCD(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(*)())two)(), 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

P: n/a
In <cu*************@zero-based.org> Martin Dickopp <ex****************@zero-based.org> writes:
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_SIMICOLON=;
flag :-)


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


I can't see *any* requirement that the output is a C program, so Case's
solution is perfectly valid, with a couple of minor fixes:
-DNOT_A_SEMICOLON=";" (the Unix shell will treat an unprotected semicolon
as a command separator, which is not what you want).

However, the program specification is so flawed that an even simpler
solution is possible: reproduce the input with no changes at all. It
works for *a* C program that doesn't contain any semicolons in the first
place ;-)

Neither solution works if we replace "a C program" by "any C program",
and "for a program" by "for a C program", but then I seriously doubt
that *any* solution exists for this program specification, except for the
following cheat: -D__NOT_A_SEMICOLON=";". No correct C program can
use the __NOT_A_SEMICOLON identifier and a compiler invoked with this
option is still a conforming C compiler ;-) Any correct C program
will be converted to a C program invoking undefined behaviour,
but that will work as expected if compiled by a conforming compiler
invoked with the "magic" option.

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

P: n/a
Dan Pop wrote:
In <cu*************@zero-based.org> Martin Dickopp <ex****************@zero-based.org> writes:
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_SIMICOLON=;
flag :-)
A compiler invoked with such a flag is *not* a conforming C
implementation.


I can't see *any* requirement that the output is a C program, so Case's
solution is perfectly valid, with a couple of minor fixes:
-DNOT_A_SEMICOLON=";" (the Unix shell will treat an unprotected semicolon
as a command separator, which is not what you want).


No, this doesn't handle semicolons in strings.
However, the program specification is so flawed that an even simpler
solution is possible: reproduce the input with no changes at all. It
works for *a* C program that doesn't contain any semicolons in the first
place ;-)


Cute, but misguided. Admittedly "a" is in some respect ambiguous
between "any" and "a certain", but it can't be reasonably interpreted
as "a certain" in the text at the top of this post. When K&R write

Write a program that reads a C program and prints in alphabetical
order each group of variable names that are identical in the first
6 characters [...] (Exercise 6.2)

do you think that they are asking for a solution that only works on a
particular program of your choosing? There are plenty more such
examples. I think "so flawed" is pretty unreasonable: I don't think
you're in any doubt as to what the specification means.

Jeremy.
Nov 14 '05 #22

P: n/a
In <sl*******************@kaje.cl.cam.ac.uk> Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
Dan Pop wrote:
In <cu*************@zero-based.org> Martin Dickopp <ex****************@zero-based.org> writes:
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_SIMICOLON=;
flag :-)

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


I can't see *any* requirement that the output is a C program, so Case's
solution is perfectly valid, with a couple of minor fixes:
-DNOT_A_SEMICOLON=";" (the Unix shell will treat an unprotected semicolon
as a command separator, which is not what you want).


No, this doesn't handle semicolons in strings.


This is true, but unimportant: handling character and string literals is
a doable and relatively minor task.
However, the program specification is so flawed that an even simpler
solution is possible: reproduce the input with no changes at all. It
works for *a* C program that doesn't contain any semicolons in the first
place ;-)


Cute, but misguided. Admittedly "a" is in some respect ambiguous
between "any" and "a certain", but it can't be reasonably interpreted
as "a certain" in the text at the top of this post. When K&R write

Write a program that reads a C program and prints in alphabetical
order each group of variable names that are identical in the first
6 characters [...] (Exercise 6.2)

do you think that they are asking for a solution that only works on a
particular program of your choosing? There are plenty more such
examples. I think "so flawed" is pretty unreasonable: I don't think
you're in any doubt as to what the specification means.


My doubts are irrelevant. The fact is that your specification *can* be
interpreted as handling a single C program and generating a Fortran
program as output. And if I want to be really picky, I can point out that
according to the C standard, pretty much anything counts as a C program :-)
That's why I usually use the term "correct C program".

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

P: n/a
Martin Dickopp wrote:
Thomas Matthews <Th*************************@sbcglobal.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


Actually, many replies have been posted. Some suggestions,
some actual answers.

http://www.google.com/groups?as_q=wi...=&num=50&hl=en
--
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

Nov 14 '05 #24

P: n/a
Thomas Matthews <Th****************************@sbcglobal.net> writes:
Martin Dickopp wrote:
Thomas Matthews <Th*************************@sbcglobal.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. :)


Actually, many replies have been posted. Some suggestions, some
actual answers.

http://www.google.com/groups?as_q=wi...=&num=50&hl=en


A lot of examples of programs without semicolon have been posted, but
that is not at all what Jeremy asked about. Unless I adopt Dan's
interpretation of "a C program", I still don't see anything which comes
close to Jeremy's specification.

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

P: n/a

On Wed, 12 May 2004, Dan Pop wrote:

Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
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_SIMICOLON=;

(s/SIMICOLON/SEMICOLON/ of course.)
No, this doesn't handle semicolons in strings.


This is true, but unimportant: handling character and string literals is
a doable and relatively minor task.


I considered this point when I wrote the "print a semicolon without
using a semicolon" program (which BTW it only now occurs to me could
have been a lot shorter!). As far as I can tell, there is *no* way to
produce the sstring literal ";" nor the character literal ';' in a
confroming C program, without using at least one semicolon.
(Character-encoding-specific hacks excluded, of course.)
Does Dan Pop see something I don't? (That's a common occurrence,
but it strikes me as unlikely in this case.)

-Arthur
Nov 14 '05 #26

P: n/a
Arthur J. O'Dwyer wrote:
On Wed, 12 May 2004, Dan Pop wrote:
Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
>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_SIMICOLON=;

(s/SIMICOLON/SEMICOLON/ of course.)

No, this doesn't handle semicolons in strings.
This is true, but unimportant: handling character and string literals is
a doable and relatively minor task.

I considered this point when I wrote the "print a semicolon without
using a semicolon" program (which BTW it only now occurs to me could
have been a lot shorter!). As far as I can tell, there is *no* way to
produce the sstring literal ";" nor the character literal ';' in a


(s/sstring/string/ of course.)
confroming C program, without using at least one semicolon.
(s/confroming/conforming/ of course.)
(Character-encoding-specific hacks excluded, of course.)
Does Dan Pop see something I don't? (That's a common occurrence,
but it strikes me as unlikely in this case.)

-Arthur


:-) Kees
Nov 14 '05 #27

P: n/a
In <Pi***********************************@unix41.andr ew.cmu.edu> "Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> writes:

On Wed, 12 May 2004, Dan Pop wrote:

Jeremy Yallop <je****@jdyallop.freeserve.co.uk> writes:
>>> 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_SIMICOLON=;
(s/SIMICOLON/SEMICOLON/ of course.)
>No, this doesn't handle semicolons in strings.


This is true, but unimportant: handling character and string literals is
a doable and relatively minor task.


I considered this point when I wrote the "print a semicolon without
using a semicolon" program (which BTW it only now occurs to me could
have been a lot shorter!). As far as I can tell, there is *no* way to
produce the sstring literal ";" nor the character literal ';' in a
confroming C program, without using at least one semicolon.
(Character-encoding-specific hacks excluded, of course.)
Does Dan Pop see something I don't? (That's a common occurrence,
but it strikes me as unlikely in this case.)


Since you have the NOT_A_SEMICOLON macro, you can build the ";" string
literal using the method documented in the FAQ. Once you have this
string, it is trivial to obtain the value of the ';' character. No
character set dependencies involved.

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

This discussion thread is closed

Replies have been disabled for this discussion.