Trigraphs & entry

Discussion in 'C Programming' started by Vijay Kumar R Zanvar, Nov 4, 2003.

  1. 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.
     
    Vijay Kumar R Zanvar, Nov 4, 2003
    #1
    1. Advertising

  2. Vijay Kumar R Zanvar

    Jack Klein Guest

    On Tue, 4 Nov 2003 09:52:03 +0530, "Vijay Kumar R Zanvar"
    <> 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
     
    Jack Klein, Nov 4, 2003
    #2
    1. Advertising

  3. Vijay Kumar R Zanvar

    pzinnc296 Guest

    "Vijay Kumar R Zanvar" <> wrote in message
    news:bo79gc$1a1uu1$-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.
     
    pzinnc296, Nov 4, 2003
    #3
  4. "pzinnc296" <> wrote in message
    news:SUGpb.176863$...

    [..]

    > 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] ?
     
    Vijay Kumar R Zanvar, Nov 4, 2003
    #4
  5. Vijay Kumar R Zanvar

    Chris Torek Guest

    In article <bo7gjj$1a21i0$-berlin.de>
    Vijay Kumar R Zanvar <> 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 (40°39.22'N, 111°50.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.
     
    Chris Torek, Nov 4, 2003
    #5
  6. "Chris Torek" <> wrote in message
    news:bo7hu0$5m1$...
    [..]
    > >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.
     
    Vijay Kumar R Zanvar, Nov 4, 2003
    #6
  7. 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
     
    Giorgio Pastore, Nov 4, 2003
    #7
  8. Vijay Kumar R Zanvar

    rihad Guest

    On 3 Nov 2003 23:45:20 -0700, Chris Torek <> wrote:

    > In-Real-Life: Chris Torek, Wind River Systems
    > Salt Lake City, UT, USA (40œ39.22'N, 111œ50.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"? :)
     
    rihad, Nov 4, 2003
    #8
  9. 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
    ¬¹²³¼½¸·⅛£¤⅜â…⅞™±°¿¸¯`×÷˙¦ΩÅ€®Ŧ¥↑ıØިƧêŊĦÅË©`'º
     
    Sheldon Simms, Nov 4, 2003
    #9
  10. Re: Trigraphs & entry [OT]

    "Vijay Kumar R Zanvar" <> wrote in message news:<bo79gc$1a1uu1$-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>
     
    August Derleth, Nov 4, 2003
    #10
  11. On Tue, 4 Nov 2003 09:52:03 +0530, in comp.lang.c , "Vijay Kumar R
    Zanvar" <> 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 donùt 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 =---
     
    Mark McIntyre, Nov 5, 2003
    #11
  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 wuth Alt Gr) but not the
    curly ones and it would be possible to write C programs without arrays
    but not without { } :-(


    Giorgio Pastore
     
    Giorgio Pastore, Nov 5, 2003
    #12
  13. 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
     
    Giorgio Pastore, Nov 5, 2003
    #13
  14. Re: Trigraphs & entry [OT]

    "August Derleth" <> wrote in message
    news:...
    > "Vijay Kumar R Zanvar" <> wrote in message

    news:<bo79gc$1a1uu1$-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
     
    Glen Herrmannsfeldt, Nov 5, 2003
    #14
  15. On Wed, 05 Nov 2003 11:54:04 +0100, in comp.lang.c , Giorgio Pastore
    <> 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 =---
     
    Mark McIntyre, Nov 5, 2003
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christopher Benson-Manica

    Trigraphs

    Christopher Benson-Manica, Sep 12, 2003, in forum: C Programming
    Replies:
    33
    Views:
    1,328
    Tom Zych
    Sep 18, 2003
  2. Daniel Rudy

    Trigraphs

    Daniel Rudy, Nov 7, 2005, in forum: C Programming
    Replies:
    39
    Views:
    1,337
    Michael Wojcik
    Jan 6, 2006
  3. Ben Bacarisse

    Re: trigraphs, yecch

    Ben Bacarisse, Jan 31, 2012, in forum: C Programming
    Replies:
    9
    Views:
    275
    James Kuyper
    Feb 1, 2012
  4. Peter Nilsson

    Re: trigraphs, yecch

    Peter Nilsson, Jan 31, 2012, in forum: C Programming
    Replies:
    7
    Views:
    232
    Ben Bacarisse
    Feb 1, 2012
  5. Keith Thompson

    Re: trigraphs, yecch

    Keith Thompson, Jan 31, 2012, in forum: C Programming
    Replies:
    20
    Views:
    536
    Joachim Schmitz
    Feb 7, 2012
Loading...

Share This Page