473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Trigraphs & entry

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.

Nov 13 '05 #1
14 8370
On Tue, 4 Nov 2003 09:52:03 +0530, "Vijay Kumar R Zanvar"
<vi***********@globaledgesoft.com> wrote in comp.lang.c:
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.
Thanks.


--
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
Nov 13 '05 #2

"Vijay Kumar R Zanvar" <vi***********@globaledgesoft.com> wrote in message
news:bo*************@ID-203837.news.uni-berlin.de...
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.

Nov 13 '05 #3

"pzinnc296" <pz*******@rogers.com> wrote in message
news:SU********************@twister01.bloor.is.net .cable.rogers.com...

[..]
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] ?


Nov 13 '05 #4
In article <bo*************@ID-203837.news.uni-berlin.de>
Vijay Kumar R Zanvar <vi***********@globaledgesoft.com> writes:
... 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?)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 13 '05 #5

"Chris Torek" <no****@elf.eng.bsdi.com> wrote in message
news:bo**********@elf.eng.bsdi.com...
[..]
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.
Nov 13 '05 #6
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

Nov 13 '05 #7
On 3 Nov 2003 23:45:20 -0700, Chris Torek <no****@elf.eng.bsdi.com> wrote:
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://67.40.109.61/torek/index.html (for the moment)


Chris, how's work going on the "C for Smarties (work in progress)"
(<http://67.40.109.61/torek/c/index.html>)? The webpage says it was last updated
on 10 Jun 2001. Will it be out "real soon now"? :)
Nov 13 '05 #8
On Tue, 04 Nov 2003 09:56:02 +0100, Giorgio Pastore wrote:
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 !


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
¬¹²³¼½¸·⅛£¤⅜⅝⅞™±°¿¸¯`×÷ ˙¦ΩŁ€®Ŧ¥↑ıØިƧЪŊĦŁ˝©`'º

Nov 13 '05 #9
"Vijay Kumar R Zanvar" <vi***********@globaledgesoft.com> wrote in message news:<bo*************@ID-203837.news.uni-berlin.de>...

<snip>
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>
Nov 13 '05 #10
On Tue, 4 Nov 2003 09:52:03 +0530, in comp.lang.c , "Vijay Kumar R
Zanvar" <vi***********@globaledgesoft.com> wrote:
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 dont even get ,e
stqrted on the qngles::::
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #11
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

Nov 13 '05 #12
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

Nov 13 '05 #13

"August Derleth" <li***************@yahoo.com> wrote in message
news:b6*************************@posting.google.co m...
"Vijay Kumar R Zanvar" <vi***********@globaledgesoft.com> wrote in message news:<bo*************@ID-203837.news.uni-berlin.de>...
<snip>
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


Nov 13 '05 #14
On Wed, 05 Nov 2003 11:54:04 +0100, in comp.lang.c , Giorgio Pastore
<pa*****@univ.trieste.it> wrote:
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.


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

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #15

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

Similar topics

2
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
39
by: Daniel Rudy | last post by:
What exactly are trigraphs, and why are they undesireable? -- Daniel Rudy Email address has been base64 encoded to reduce spam Decode email address using b64decode or uudecode -m Why...
6
by: Geoffrey S. Knauth | last post by:
It's been a while since I programmed in C++, and the language sure has changed. Usually I can figure out why something no longer compiles, but this time I'm stumped. A friend has a problem he...
7
by: John Nagle | last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&amp;". Is there some way I can get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.