Returning int pointer ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CBFalconer

    #46
    Re: Returning int pointer ?

    Malcolm McLean wrote:
    "Phil Carmody" <thefatphil_dem unged@yahoo.co. ukwrote:
    >
    >>You assume that a char holds a character in the execution
    >>character set. If it doesn't you theoretically risk trap
    >>representatio ns.
    >>
    >I thought character types were specifically excluded from trap
    >representation s?
    >
    unsigned char is, signed char not.
    However signed char is guaranteed 8 bits, so in fact it can hold
    ASCII codes. Plain char must be an alias for either signed char
    or unsigned char. So Keith Thompson actually squeaks through.
    And the chars in the basic execution set must always be positive.
    This forces EBCDIC based systems to used unsigned char as the type
    for char. on byte machines.

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home .att.net>
    Try the download section.

    Comment

    • Keith Thompson

      #47
      Re: Returning int pointer ?

      CBFalconer <cbfalconer@yah oo.comwrites:
      [...]
      And the chars in the basic execution set must always be positive.
      Quibble: they must be non-negative. The null character is in the
      basic execution character set.
      This forces EBCDIC based systems to used unsigned char as the type
      for char. on byte machines.
      Another quibble: it forces EBCDIC based systems to make plain char an
      unsigned type. char and unsigned char are still distinct types, even
      if they have the same range and representation.

      --
      Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
      Nokia
      "We must do something. This is something. Therefore, we must do this."
      -- Antony Jay and Jonathan Lynn, "Yes Minister"

      Comment

      • Keith Thompson

        #48
        Re: Returning int pointer ?

        CBFalconer <cbfalconer@yah oo.comwrites:
        Richard Heathfield wrote:
        >CBFalconer said:
        >>Malcolm McLean wrote:
        >>>>
        >>... snip ...
        >>>>
        >>>Finally terrible news comes in. We've implemented writeasciiz as
        >>>>
        >>>int writeasciiz(cha r *str, FILE *fp) {
        >>> while (*str)
        >>> fputc(*str++, fp);
        >>> fputc(0, fp);
        >>> return ferror(fp) ? EOF : 0;
        >>>}
        >>>>
        >>>Of course this won't cut the mustard when we move to a non-ascii
        >>>machine.
        >>>
        >>Why not?
        >>
        >Because on a non-ASCII machine, it won't write ASCII. It will write
        >the native character set. For example, on a typical IBM mainframe
        >using EBCDIC, if you call it thusly:
        >
        Don't be a slave to the OPs misnaming of the routine. He wants to
        write a string. The routine will write whatever characters have
        been placed in the string, and the char format doesn't matter.
        That is one more reason the C standard doesn't specify the char
        coding.
        How do you know what the OP wants writeasciiz to do? (I think it was
        Malcolm McLean who introduced the function.) For all we know, he
        wants it to write ASCII characters even on an EBCDIC system, and the
        implementation he's shown us is incomplete. If he wants to provide
        some documentation, we can discuss it; until then, there's not much
        point in guessing.
        He doesn't even need the "fputc(0, fp);" line.
        Why not? The intent appears to be to write the characters of the
        string followed by a null character; that's presumably what the 'z' at
        the end of the name means. (This makes sense only if fp was opened in
        binary mode.)

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
        Nokia
        "We must do something. This is something. Therefore, we must do this."
        -- Antony Jay and Jonathan Lynn, "Yes Minister"

        Comment

        • Richard Heathfield

          #49
          Re: Returning int pointer ?

          Keith Thompson said:
          CBFalconer <cbfalconer@yah oo.comwrites:
          [...]
          >And the chars in the basic execution set must always be positive.
          >
          Quibble: they must be non-negative. The null character is in the
          basic execution character set.
          >
          >This forces EBCDIC based systems to used unsigned char as the type
          >for char. on byte machines.
          >
          Another quibble: it forces EBCDIC based systems to make plain char an
          unsigned type.
          Quibble: no, it doesn't. They could instead make CHAR_BIT 9 or more.

          --
          Richard Heathfield <http://www.cpax.org.uk >
          Email: -http://www. +rjh@
          Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
          "Usenet is a strange place" - dmr 29 July 1999

          Comment

          • David Thompson

            #50
            Re: Returning int pointer ?

            ...
            On Sun, 26 Oct 2008 23:26:02 +0200, Phil Carmody
            <thefatphil_dem unged@yahoo.co. ukwrote:
            "Malcolm McLean" <regniztar@btin ternet.comwrite s:
            >
            "Phil Carmody" <thefatphil_dem unged@yahoo.co. ukwrote in message
            I thought character types were specifically excluded from trap
            representations ?
            >
            unsigned char is, signed char not.
            >
            Is that so?
            <snip 6.2.5p15, 6.2.6.1p5>
            I'm not seeing a distinction between unsigned char and signed char
            when it comes to trap representations .
            >
            That's 1256, by the way - do you have another reference, or a
            paragraph within 1256 which says something different?
            >
            6.2.6.2p1: "For unsigned integer types other than unsigned char, ...
            padding bits [are allowed]" which allows trap reps; for uchar without
            padding (or sign) only 'pure binary' value bits, there is no trap rep.

            and p2: "For signed integer types ... padding bits [are allowed] ...
            [and max-neg can be a trap representation]".

            - formerly david.thompson1 || achar(64) || worldnet.att.ne t

            Comment

            • Phil Carmody

              #51
              Re: Returning int pointer ?

              David Thompson <dave.thompson2 @verizon.netwri tes:
              ..
              On Sun, 26 Oct 2008 23:26:02 +0200, Phil Carmody
              <thefatphil_dem unged@yahoo.co. ukwrote:
              >
              >"Malcolm McLean" <regniztar@btin ternet.comwrite s:
              >>
              "Phil Carmody" <thefatphil_dem unged@yahoo.co. ukwrote in message
              >
              >I thought character types were specifically excluded from trap
              >representation s?
              >>
              unsigned char is, signed char not.
              >>
              >Is that so?
              <snip 6.2.5p15, 6.2.6.1p5>
              >I'm not seeing a distinction between unsigned char and signed char
              >when it comes to trap representations .
              >>
              >That's 1256, by the way - do you have another reference, or a
              >paragraph within 1256 which says something different?
              >>
              6.2.6.2p1: "For unsigned integer types other than unsigned char, ...
              padding bits [are allowed]" which allows trap reps; for uchar without
              padding (or sign) only 'pure binary' value bits, there is no trap rep.
              >
              and p2: "For signed integer types ... padding bits [are allowed] ...
              [and max-neg can be a trap representation]".
              Many thanks. If it's worth reading once, it's worth reading thrice.

              Phil
              --
              We must respect the other fellow's religion, but only in the sense and to the
              extent that we respect his theory that his wife is beautiful and his children
              smart. -- Henry Louis Mencken (1880-1956), American editor and critic

              Comment

              Working...