printf() question

16 views
Skip to first unread message

Ville Ollikainen

unread,
Aug 2, 1996, 3:00:00 AM8/2/96
to ollik...@mtv3.fi

During last two days I have compiled some old 'C' files with Microsoft CL
compiler 8.00c. In one file I found a problem, which I can't explain. The
problem is reduced to the following source code:

--- source code IWONDER.C, cut here 8< ---------------------------------
#include <stdio.h>
void main( )
{
printf( "??-I wonder!\n" );
}
--- end source code IWONDER.C ------------------------------------------

When I compile, link and run it under DOS 6.22, I get out

~I wonder!

, although I expected to get

??-I wonder!

Could anyone please tell me why? The batch file I used to compile and
link the program is as follows:

--- 8< ---
@rem Microsoft (R) C/C++ Optimizing Compiler Version 8.00c
cl /c /AL Iwonder.c
@rem Microsoft (R) Segmented Executable Linker Version 5.60
link Iwonder ,,,llibce,,
type Iwonder.c
Iwonder
--- 8< ---

The string ~I wonder! exists already in the IWONDER.OBJ file.

Thanks in advance,

Ville Ollikainen
ollik...@mtv3.fi

Ken Nicolson

unread,
Aug 2, 1996, 3:00:00 AM8/2/96
to

Ville Ollikainen <ollik...@mtv3.fi> wrote:

>During last two days I have compiled some old 'C' files with Microsoft CL
>compiler 8.00c. In one file I found a problem, which I can't explain. The
>problem is reduced to the following source code:
>
>--- source code IWONDER.C, cut here 8< ---------------------------------
>#include <stdio.h>
>void main( )
>{
> printf( "??-I wonder!\n" );
>}
>--- end source code IWONDER.C ------------------------------------------
>
>When I compile, link and run it under DOS 6.22, I get out
>
>~I wonder!
>
>, although I expected to get
>
>??-I wonder!
>
>Could anyone please tell me why?

"??-" is a trigraph - here's a table of them from my on-line docs:

Trigraph Punctuation Character
??= #
??( [
??/ \
??) ]
??’ ^
??< {
??! |
??> }
??- ~ <---- Your trigraph

It's for people with keyboards that don't have the keys for these
characters.

The fix suggested by my reference manual is:

printf( "?\?-I wonder!\n" );
^ Backslash added here.

BTW, main() returns an int in C.

Ken
--
___ ,_, ___ Ken Nicolson
(o,o) (o,o) ,,,(o,o),,,
{`"'} {`"'} ';:`-':;' Work: ke...@owl.co.uk
-"-"- -"-"- -"-"- +44 131 xxx xxxx
My employer doesn't give three Home: k...@ride.demon.co.uk
hoots about my opinions. Web: http://www.ride.demon.co.uk


John Winters

unread,
Aug 2, 1996, 3:00:00 AM8/2/96
to

In article <4tt09n$l...@idefix.eunet.fi>,

Ville Ollikainen <ollik...@mtv3.fi> wrote:
>During last two days I have compiled some old 'C' files with Microsoft CL
>compiler 8.00c. In one file I found a problem, which I can't explain. The
>problem is reduced to the following source code:
>
>--- source code IWONDER.C, cut here 8< ---------------------------------
>#include <stdio.h>
>void main( )
>{
> printf( "??-I wonder!\n" );
>}
>--- end source code IWONDER.C ------------------------------------------
>
>When I compile, link and run it under DOS 6.22, I get out
>
>~I wonder!
>
>, although I expected to get
>
>??-I wonder!
>
>Could anyone please tell me why? The batch file I used to compile and
>link the program is as follows:

I find it hard to believe anyone generated a string with ??- in it by
accident. What you have there is a trigraph. I was about to refer
you to the FAQ, but then I went and had a look and it isn't mentioned
there.

Look for "trigraph" in the index of your friendly C book.

John


--
John Winters. Wallingford, Oxon, England.

spooky

unread,
Aug 2, 1996, 3:00:00 AM8/2/96
to

Ville Ollikainen <ollik...@mtv3.fi> writes:

>During last two days I have compiled some old 'C' files with Microsoft CL
>compiler 8.00c. In one file I found a problem, which I can't explain. The
>problem is reduced to the following source code:

>--- source code IWONDER.C, cut here 8< ---------------------------------
>#include <stdio.h>
>void main( )
>{
> printf( "??-I wonder!\n" );
>}
>--- end source code IWONDER.C ------------------------------------------

>When I compile, link and run it under DOS 6.22, I get out

>~I wonder!

>, although I expected to get

>??-I wonder!

>Could anyone please tell me why? The batch file I used to compile and
>link the program is as follows:

Sequences startingn with two question marks ?? are called TRIGRAPH
sequences. On some foreign keyboards you can't access all the characters
that are needed by the C standard, so aliases were created so these
keys could be typed in anyay. ??- is the alias for '~', apparaently.
I don't know of any way around it unless your compiler has a switch
to disable trigraphs.

David

Goran Larsson

unread,
Aug 2, 1996, 3:00:00 AM8/2/96
to

In article <4tt09n$l...@idefix.eunet.fi>,
Ville Ollikainen <ollik...@mtv3.fi> wrote:
> void main( )

After this, anything can happen.

> printf( "??-I wonder!\n" );

The trigraphs has to go!

Look in your compiler documentation for trigraphs. See of there is
a switch to disable them. Use it.

The trigraphs has to go!

> @rem Microsoft (R) Segmented Executable Linker Version 5.60
> link Iwonder ,,,llibce,,

^^^^^^^^^^^ what a perverted "user friendly" format.
What progress, Micro$oft used the same syntax 15 years ago, they
just added more comma signs...

--
Goran Larsson Phone: +46 13 299588 FAX: +46 13 299022
Approve AB +46 589 85500 +46 589 16901
h...@approve.se
I was an atheist, until I found out I was God.

Antoine Leca

unread,
Aug 5, 1996, 3:00:00 AM8/5/96
to

Goran Larsson wrote:
>
> In article <4tt09n$l...@idefix.eunet.fi>,
> Ville Ollikainen <ollik...@mtv3.fi> wrote:<snip>
> > printf( "??-I wonder!\n" );
>
> The trigraphs has to go!
>
> Look in your compiler documentation for trigraphs. See of there
> is a switch to disable them. Use it.

I thing there isn't...

>
> The trigraphs has to go!

> <rest deleted>

I'm not OK with you.
There is a lot of machines (and particulary printers) which can't
handle properly some characters, and therefore which need special
translations in order to, for example, seeing the code...

Others problems of this type are, for example, the ! and the |
reversed on non-US EBCDIC machines with US-only compilers: then you
obtain things like this:
if( i==0 !! j==0 !! |p )
k != MASK_OK;
Look funny, no?

I agree that trigraphes are ugly (and this is intented, in order to
dissuade their use), and that few people are aware of this pitfall
(hence this thread), especially in Macintosh world where the
character constant '????' is of common use.

I agree that a trigraph-disabling option would be a great addition,
especially in environments where trigraphs are rare like in MS-DOS
or even UNIX.

But trigraphs hadn't to go, since they are a necessary thing for
portability of C. And portability is one of the greatest feature
of C, isn't it?


Antoine Leca

Goran Larsson

unread,
Aug 5, 1996, 3:00:00 AM8/5/96
to

In article <3205BE...@Renault.Fr>,
Antoine Leca <Antoin...@Renault.Fr> wrote:

> Goran Larsson wrote:
> > The trigraphs has to go!
> I'm not OK with you.
> There is a lot of machines (and particulary printers) which can't
> handle properly some characters, and therefore which need special
> translations in order to, for example, seeing the code...

>
> Others problems of this type are, for example, the ! and the |
> reversed on non-US EBCDIC machines with US-only compilers: then you
> obtain things like this:
> if( i==0 !! j==0 !! |p )
> k != MASK_OK;
> Look funny, no?

Yes, it looks funny. But with trigraphs it would look plain stupid.
And what is even more funny is that there is NO trigraph for "!", so
this "problem" can't even be solved with trigraphs!
The following trigraphs is defined:
??= #
??/ \
??' ^
??( [
??) ]
??! |
??< {
??> }
??- ~
If you have a os/compiler combination that reverses | and !, then what
does ??! mean? If the ! is replaced by | we have ??| wich is an invalid
trigraph... What a mess.

> But trigraphs hadn't to go, since they are a necessary thing for
> portability of C. And portability is one of the greatest feature
> of C, isn't it?

C was portable long before trigraphs were "invented". I have never seen
a C program using trigraphs (except for some Obfuscated C Code Contest
programs) and can't imagine how anyone would write a C program using
trigraphs and still remain sane.

Have anyone actually had to use trigraphs for anything usefull?

Kohn Emil Dan

unread,
Aug 7, 1996, 3:00:00 AM8/7/96
to


On 2 Aug 1996, Ville Ollikainen wrote:

> During last two days I have compiled some old 'C' files with Microsoft CL
> compiler 8.00c. In one file I found a problem, which I can't explain. The
> problem is reduced to the following source code:

<snipped>


> --- source code IWONDER.C, cut here 8< ---------------------------------
> #include <stdio.h>
> void main( )
> {

> printf( "??-I wonder!\n" );
> }

> --- end source code IWONDER.C ------------------------------------------
>
> When I compile, link and run it under DOS 6.22, I get out
>
> ~I wonder!
>
> , although I expected to get
>
> ??-I wonder!
>
> Could anyone please tell me why? The batch file I used to compile and
> link the program is as follows:

The ??- is a trigraph sequence. It is used to introduce characters that
are not available on some keyboards with special national characters, but
are used by the C language. So '??-' is the trigraph sequence for '~'. In
order to solve the problem, you should escape each question mark with a
backslash, so the string passed to printf() should be:

"\?\?-I wonder!\n"

And last, but not least. In C, main() returns an int, not void.

Hope this helps.

Regards,

Emil

Reply all
Reply to author
Forward
0 new messages