Trigraphs & entry

  • Thread starter Vijay Kumar R Zanvar
  • Start date
V

Vijay Kumar R Zanvar

I have following questions:

1. Appendix C of K&R says:
Trigraph sequences introduced by ?? allow
representation of characters lacking in some
character sets. ...

Can somebody explain how trigraphs are used?

2. What `entry' keyword was used for?

3. How to support colored output in C? For example,
Turbo C/C++ provides textattr () and textcolor ()
library routines to support it.

Thanks.
 
J

Jack Klein

I have following questions:

1. Appendix C of K&R says:
Trigraph sequences introduced by ?? allow
representation of characters lacking in some
character sets. ...

Can somebody explain how trigraphs are used?
Pass.

2. What `entry' keyword was used for?

Some C compilers prior to the standard implemented that keyword.
Since it was never part of any version of the C standard, it has no
defined standardized meaning. So it was used for whatever the
compiler implementor wanted to use it for.
3. How to support colored output in C? For example,
Turbo C/C++ provides textattr () and textcolor ()
library routines to support it.

Use compiler-specific non-standard extensions provided by whatever
compiler you are using, just as you did those with Turbo C. Since C
does not define, support, or require a video display, it has no
support for color.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
P

pzinnc296

Vijay Kumar R Zanvar said:
I have following questions:

1. Appendix C of K&R says:
Trigraph sequences introduced by ?? allow
representation of characters lacking in some
character sets. ...

Can somebody explain how trigraphs are used?
Just like it says in K&R: to make up for characters not existing in a
specific
codepage. The only example I know is certain mainframe computers that don't
have the characters [ and ] in their codepage (along with some less
frequently used characters). These characters should be expanded in ??( and
??) respectively before uploading.
If you want to write truly compatibel C code, your lines should be within 80
characters
AFTER trigraph expansion. If you don't intend to port to older mainframes, I
wouldn't know why you should bother.
 
V

Vijay Kumar R Zanvar

[..]
Just like it says in K&R: to make up for characters not existing in a
specific
codepage. The only example I know is certain mainframe computers that don't
have the characters [ and ] in their codepage (along with some less
frequently used characters). These characters should be expanded in ??( and
??) respectively before uploading.
If you want to write truly compatibel C code, your lines should be within 80
characters
AFTER trigraph expansion. If you don't intend to port to older mainframes, I
wouldn't know why you should bother.

Questions 1 and 2 were just to calm my curiosities.
If you know an simple code example, I will be grateful
to have a look at it.


K&R II, Section A12.1:

... In order to enable programs to be represented in
the reduced set, all occurences of the following trigraphs
sequences are replaced by the corresponding single character.
**This replacement occur before any other processing.**

...

So, in the following program:

#include <stdio.h>

int
main ( void )
{
char a[] = "??(abc??)"; /* Should it be: char a??(??) = "..."; ?
*/
puts ( a );
exit ( 0 );
}

the output is: ??(abc??).
Should if not be [abc] ?
 
C

Chris Torek

... in the following program: [snippage]
char a[] = "??(abc??)"; /* Should it be: char a??(??) = "..."; ? */
puts ( a );
the output is: ??(abc??).
Should if not be [abc] ?

It should be, and it is here:

% cc -ansi -pedantic -W -Wall -O -o t t.c
t.c: warning: 4 trigraph(s) encountered
% ./t
[abc]
%

You may use the trigraph syntax as shown in the comment if you
wish, too.

Note that without the "-ansi" switch, gcc stops recognizing
trigraphs:

% cc -pedantic -W -Wall -O -o t t.c
% ./t
??(abc??)
%

I have never found anyone who *likes* trigraphs (even on IBM systems
with their wacky code page problems :) ), and most people never seem
to use them. As a result, at least this one compiler (gcc) pretends
they do not exist by default; you must explicitly (-trigraphs) or
implicitly (-ansi) enable them. (The compiler runs more slowly when
they are turned on, too, although with today's multi-gigahertz CPUs,
who really notices?)
 
V

Vijay Kumar R Zanvar

[..]
the output is: ??(abc??).
Should if not be [abc] ?

It should be, and it is here:

% cc -ansi -pedantic -W -Wall -O -o t t.c
t.c: warning: 4 trigraph(s) encountered
% ./t
[abc]
%

[..]

Thanks. It was almost like a climax! :) Now I understood.
 
G

Giorgio Pastore

Chris Torek wrote:
....
I have never found anyone who *likes* trigraphs (even on IBM systems
with their wacky code page problems :) ), and most people never seem
to use them.

True, if one uses US keyboards. But think what would be your opinion if
you should write a C program using a variety of keyboards including, for
example, the italian one where there is no curly or square bracket at all !

I admit that I do not like *to see* trigraphs in C code. But I *like*
them very much if I have to write C code using a keyboard missing some
keys crucial for C. Luckly, who put them in the standard was aware of
the problems of a multicultural world.


Giorgio Pastore
 
S

Sheldon Simms

Chris Torek wrote:
...

True, if one uses US keyboards. But think what would be your opinion if
you should write a C program using a variety of keyboards including, for
example, the italian one where there is no curly or square bracket at all !

Just curious, but is this true of current italian keyboards, or
just old ones?

I, for example, use a german keyboard. All of the required characters
are there, but many of them require using the "Alt Gr" key, from
which I infer that older german keyboards simply did not have them.

As a bonus, the presence of the Alt Gr key also lets me type other
characters that are difficult to find on a standard US keyboard
¬¹²³¼½¸·⅛£¤⅜â…⅞™±°¿¸¯`×÷˙¦ΩÅ€®Ŧ¥↑ıØިƧêŊĦÅË©`'º
 
A

August Derleth

2. What `entry' keyword was used for?
[off-topic]

The entry keyword was intended to provide subroutines with more than
one point of entry. That way, you could write one block of code and
have it `stand in for' different subroutines, because different calls
would deposit you to different places within the code.

The problem with this is obvious: It reduces subroutine calls to
gotos, and it makes it difficult to predict exactly where the next
step of the program would take you. It /could/ be used in structured
code, but only with care. Besides that, it really offers nothing real
subroutines don't.

The concept was borrowed from FORTRAN and was part of very early
designs of C. Apparently, some compiler designers did implement it,
but I've never seen an implementation that actually used the entry
keyword.

Really, it isn't a big loss. The concept of one subroutine with
multiple entry points was on its way out even before C was new, and it
was wise of the standards makers to ignore such a half-baked idea.

[/off-topic]
<snip>
 
M

Mark McIntyre

I have following questions:

1. Appendix C of K&R says:
Trigraph sequences introduced by ?? allow
representation of characters lacking in some
character sets. ...

Can somebody explain how trigraphs are used?

in Days of Yore, some keyboards didn't have certain keys, such as hash
(#), or angles <>. To get round this, the C standard defined trigraphs
that you can use instead.

Bizarrely I've actually used these recently. On my power mac G3
keyboard I can never remember how to type the hash key, so I use the
trigraph ??= instead. (For the uninitiated, Beige G3s have the
sterling symbol on shift-3, and the / above the right-shift. Hash is
not on the menu).

I've also used them when typing on French keyboard layouts with UK
keyboards as its quicker than mollocking around trying to second-guess
zhere the blqsted hqsh key hqs vqnished to: Qnd donùt even get ,e
stqrted on the qngles::::
 
G

Giorgio Pastore

Sheldon Simms wrote:
....
Just curious, but is this true of current italian keyboards, or
just old ones?
I, for example, use a german keyboard. All of the required characters
are there, but many of them require using the "Alt Gr" key, from
which I infer that older german keyboards simply did not have them.


Some have the square brackets (to be used wuth Alt Gr) but not the
curly ones and it would be possible to write C programs without arrays
but not without { } :-(


Giorgio Pastore
 
G

Giorgio Pastore

Sheldon Simms wrote:
....
Just curious, but is this true of current italian keyboards, or
just old ones?

I, for example, use a german keyboard. All of the required characters
are there, but many of them require using the "Alt Gr" key, from
which I infer that older german keyboards simply did not have them.

Some have the square brackets (to be used with Alt Gr) but in general
there is no curly bracket. Not a nice feature for C programmers ! And
even worse if you have to *teach* C.

Giorgio Pastore
 
G

Glen Herrmannsfeldt

August Derleth said:
"Vijay Kumar R Zanvar" <[email protected]> wrote in message
2. What `entry' keyword was used for?
[off-topic]

The entry keyword was intended to provide subroutines with more than
one point of entry. That way, you could write one block of code and
have it `stand in for' different subroutines, because different calls
would deposit you to different places within the code.

In PL/I the ENTRY keyword is used for both multiple entry to procedures, and
also for declaring procedure names. In C the () pretty much identify a
function name so that the entry attribute is not needed. PL/I allows
functions without any argument list, so the ENTRY attribute is needed to
declare them.

The C declaration double sqrt(); in PL/I would be DCL SQRT ENTRY
RETURNS(FLOAT BINARY(53)); though RETURNS implies ENTRY in this case, so
the ENTRY attribute is really only needed when nothing is returned.
The problem with this is obvious: It reduces subroutine calls to
gotos, and it makes it difficult to predict exactly where the next
step of the program would take you. It /could/ be used in structured
code, but only with care. Besides that, it really offers nothing real
subroutines don't.

Like many language features, it can be used for good or evil. The C file
scope variables reduce the need for it. One example in other languages
might be a random number generator and its initialization/seed call.
Another obvious example is the sin() and cos() entries to a routine that can
compute either of them. Multiple entry points are a little more memory and
time efficient in both cases, though faster computers have reduced the
importance of both.
The concept was borrowed from FORTRAN and was part of very early
designs of C. Apparently, some compiler designers did implement it,
but I've never seen an implementation that actually used the entry
keyword.

It is complicated in the case of functions, where different entry points
might have a different return type. When you have multiple entries into a
function, and the entries have a different return type, it greatly
complicates the return statement. In Fortrans that implement ENTRY,
functions return a value by assigning it to a variable named after the
function, so the compiler knows the type to convert it to. (All the names
are EQUIVALENCEd, somewhat similar to C's union, though they are required to
overlap in memory.) PL/I seems to have the ability to convert the type of
the return value to the type of any of the entry points. Possibly the
conversion requirement was enough to remove it from consideration for C.
Really, it isn't a big loss. The concept of one subroutine with
multiple entry points was on its way out even before C was new, and it
was wise of the standards makers to ignore such a half-baked idea.

Another reason it isn't needed so much is the va_arg feature of C. In
languages that have multiple entry points, one use for them is to implement
different argument types or number of arguments. (Consider the atan() and
atan2() functions, though va_arg doesn't help much there.) The small number
of cases where it would be needed can be implemented by having functions
with the required arguments all call a common function. In those cases,
though, I would say that mulitple entries are more readable.

-- glen
 
M

Mark McIntyre

Sheldon Simms wrote:
...

Some have the square brackets (to be used with Alt Gr) but in general
there is no curly bracket. Not a nice feature for C programmers ! And
even worse if you have to *teach* C.

You think that's bad? Try a greek or russian keyboard !!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,198
Latest member
JaimieWan8

Latest Threads

Top