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. | | | | re: Trigraphs & entry
On Tue, 4 Nov 2003 09:52:03 +0530, "Vijay Kumar R Zanvar"
<vijaykumar.rz@globaledgesoft.com> wrote in comp.lang.c:
[color=blue]
> 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?[/color]
Pass.
[color=blue]
> 2. What `entry' keyword was used for?[/color]
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.
[color=blue]
> 3. How to support colored output in C? For example,
> Turbo C/C++ provides textattr () and textcolor ()
> library routines to support it.[/color]
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.
[color=blue]
> Thanks.[/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 | | | | re: Trigraphs & entry
"Vijay Kumar R Zanvar" <vijaykumar.rz@globaledgesoft.com> wrote in message
news:bo79gc$1a1uu1$1@ID-203837.news.uni-berlin.de...[color=blue]
> 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?
>[/color]
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. | | | | re: Trigraphs & entry
"pzinnc296" <pzinnc296@rogers.com> wrote in message
news:SUGpb.176863$3f.152336@twister01.bloor.is.net .cable.rogers.com...
[..]
[color=blue]
> 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[/color]
don't[color=blue]
> have the characters [ and ] in their codepage (along with some less
> frequently used characters). These characters should be expanded in[/color]
??( and[color=blue]
> ??) respectively before uploading.
> If you want to write truly compatibel C code, your lines should be[/color]
within 80[color=blue]
> characters
> AFTER trigraph expansion. If you don't intend to port to older[/color]
mainframes, I[color=blue]
> wouldn't know why you should bother.[/color]
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] ? | | | | re: Trigraphs & entry
In article <bo7gjj$1a21i0$1@ID-203837.news.uni-berlin.de>
Vijay Kumar R Zanvar <vijaykumar.rz@globaledgesoft.com> writes:[color=blue]
>... in the following program:[/color]
[snippage][color=blue]
> char a[] = "??(abc??)"; /* Should it be: char a??(??) = "..."; ? */
> puts ( a );[/color]
[color=blue]
>the output is: ??(abc??).
>Should if not be [abc] ?[/color]
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. | | | | re: Trigraphs & entry
"Chris Torek" <nospam@elf.eng.bsdi.com> wrote in message
news:bo7hu0$5m1$1@elf.eng.bsdi.com...
[..][color=blue][color=green]
> >the output is: ??(abc??).
> >Should if not be [abc] ?[/color]
>
> 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]
> %[/color]
[..]
Thanks. It was almost like a climax! :-) Now I understood. | | | | re: Trigraphs & entry
Chris Torek wrote:
....[color=blue]
> 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.[/color]
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 | | | | re: Trigraphs & entry
On 3 Nov 2003 23:45:20 -0700, Chris Torek <nospam@elf.eng.bsdi.com> wrote:
[color=blue]
> 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)[/color]
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"? :) | | | | re: Trigraphs & entry
On Tue, 04 Nov 2003 09:56:02 +0100, Giorgio Pastore wrote:
[color=blue]
> Chris Torek wrote:
> ...[color=green]
>> 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.[/color]
>
> 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 ![/color]
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
¬¹²³¼½¸·⅛£¤⅜⅝⅞™±°¿¸¯`×÷ ˙¦ΩŁ€®Ŧ¥↑ıØÞ¨Æ§ÐªŊĦŁ˝©`'º | | | | re: Trigraphs & entry
"Vijay Kumar R Zanvar" <vijaykumar.rz@globaledgesoft.com> wrote in message news:<bo79gc$1a1uu1$1@ID-203837.news.uni-berlin.de>...
<snip>
[color=blue]
> 2. What `entry' keyword was used for?[/color]
[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> | | | | re: Trigraphs & entry
On Tue, 4 Nov 2003 09:52:03 +0530, in comp.lang.c , "Vijay Kumar R
Zanvar" <vijaykumar.rz@globaledgesoft.com> wrote:
[color=blue]
>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?[/color]
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 =--- | | | | re: Trigraphs & entry
Sheldon Simms wrote:
....[color=blue]
> Just curious, but is this true of current italian keyboards, or
> just old ones?[/color]
[color=blue]
> 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.[/color]
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 | | | | re: Trigraphs & entry
Sheldon Simms wrote:
....[color=blue]
> 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.[/color]
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 | | | | re: Trigraphs & entry
"August Derleth" <libertarian232003@yahoo.com> wrote in message
news:b6c8998.0311041545.7dbf12bb@posting.google.co m...[color=blue]
> "Vijay Kumar R Zanvar" <vijaykumar.rz@globaledgesoft.com> wrote in message[/color]
news:<bo79gc$1a1uu1$1@ID-203837.news.uni-berlin.de>...[color=blue]
>
> <snip>
>[color=green]
> > 2. What `entry' keyword was used for?[/color]
> [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.[/color]
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.
[color=blue]
> 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.[/color]
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.
[color=blue]
> 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.[/color]
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.
[color=blue]
> 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.[/color]
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 | | | | re: Trigraphs & entry
On Wed, 05 Nov 2003 11:54:04 +0100, in comp.lang.c , Giorgio Pastore
<pastgio@univ.trieste.it> wrote:
[color=blue]
>Sheldon Simms wrote:
>...[color=green]
>> 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.[/color]
>
>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.[/color]
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 =--- |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,439 network members.
|