Constructs

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

    #1

    Constructs

    There is a new book-ish like entity that is freely available on the web:

    "Constructs of the C++ Proramming Language"

    The book is intended to serve as a light-weight reference for developers
    with modest experience in C++.

    Enjoy,
    Landrew


  • Landrew

    #2
    Re: Constructs

    Doh!

    To be found at www.landrew.com


    "Landrew" <news04@landrew .com> wrote in message
    news:tdCdnZBBmp tw5ybcRVn-uw@speakeasy.ne t...[color=blue]
    > There is a new book-ish like entity that is freely available on the web:
    >
    > "Constructs of the C++ Proramming Language"
    >
    > The book is intended to serve as a light-weight reference for developers
    > with modest experience in C++.
    >
    > Enjoy,
    > Landrew
    >[/color]


    Comment

    • Niels Dekker - no reply address

      #3
      Re: Constructs

      Landrew wrote:[color=blue]
      >
      > "Constructs of the C++ Proramming Language"
      >
      > To be found at www.landrew.com[/color]

      Cool! Thanks!



      says:[color=blue]
      >
      > void process()
      > {
      > char s[100] = "hop on!";
      > }
      >
      > The first seven positions in s are set to 'h', 'o', 'p', ' '
      > (space), 'o', 'n', '!'. The eigth position is set to a special
      > end of string marker, called the null character. The null
      > character is denoted by '\0' when it explicitly appears in code.[/color]

      s[8] to s[99] are set to a null character as well.

      [color=blue]
      > Thus the code above has the same effect as the following:
      >
      > void process()
      > {
      > char s[100];
      >
      > s[0] = 'h';
      > s[1] = 'o';
      > s[2] = 'p';
      > s[3] = ' ';
      > s[4] = 'o';
      > s[5] = 'n';
      > s[6] = '!';
      > s[7] = '\0'; // end of string marker (null character)
      > }[/color]

      This version will leave s[8] to s[99] uninitialized. Also it might take
      less memory during runtime, because it won't store this literal string,
      "hop on!".


      Regards,

      Niels Dekker
      Deze pagina bestaat niet of is niet meer beschikbaar. Oude XS4ALL-homepages zijn soms nog terug te vinden via webarchieven.

      Comment

      • Landrew

        #4
        Re: Constructs

        > s[8] to s[99] are set to a null character as well.

        interesting. are you certain about that? i would have thought it would be
        true for global variables, but not for local variables.

        just as this initializes x to zero

        ----
        int x;

        int main()
        {
        ...
        }
        ----

        but this does not

        ----
        int main()
        {
        int x;

        ...
        }
        ----

        at least that is what i thought :)

        landrew


        "Niels Dekker - no reply address" <unknown@this.i s.invalid> wrote in message
        news:41BC6417.2 4B2D4E6@this.is .invalid...[color=blue]
        > Landrew wrote:[color=green]
        >>
        >> "Constructs of the C++ Proramming Language"
        >>
        >> To be found at www.landrew.com[/color]
        >
        > Cool! Thanks!
        >
        >
        > https://www.landrew.com/cgi-bin/Via/...tructs/Strings
        > says:[color=green]
        >>
        >> void process()
        >> {
        >> char s[100] = "hop on!";
        >> }
        >>
        >> The first seven positions in s are set to 'h', 'o', 'p', ' '
        >> (space), 'o', 'n', '!'. The eigth position is set to a special
        >> end of string marker, called the null character. The null
        >> character is denoted by '\0' when it explicitly appears in code.[/color]
        >
        > s[8] to s[99] are set to a null character as well.
        >
        >[color=green]
        >> Thus the code above has the same effect as the following:
        >>
        >> void process()
        >> {
        >> char s[100];
        >>
        >> s[0] = 'h';
        >> s[1] = 'o';
        >> s[2] = 'p';
        >> s[3] = ' ';
        >> s[4] = 'o';
        >> s[5] = 'n';
        >> s[6] = '!';
        >> s[7] = '\0'; // end of string marker (null character)
        >> }[/color]
        >
        > This version will leave s[8] to s[99] uninitialized. Also it might take
        > less memory during runtime, because it won't store this literal string,
        > "hop on!".
        >
        >
        > Regards,
        >
        > Niels Dekker
        > http://www.xs4all.nl/~nd/dekkerware[/color]


        Comment

        • Niels Dekker - no reply address

          #5
          Re: Constructs

          www.landrew.com says:[color=blue]
          >
          > void process()
          > {
          > char s[100] = "hop on!";
          > }
          >
          > The first seven positions in s are set to 'h', 'o', 'p', ' '
          > (space), 'o', 'n', '!'. The eigth position is set to a special
          > end of string marker, called the null character. The null
          > character is denoted by '\0' when it explicitly appears in code.[/color]

          And I commented:[color=blue]
          >
          > s[8] to s[99] are set to a null character as well.[/color]

          Landrew wrote:[color=blue]
          >
          > interesting. are you certain about that?[/color]

          Well... home.tiscalinet .ch/t_wolf/tw/c/string_init.htm l says:[color=blue]
          >
          > yes, if a string literal in an initializer contains less characters
          > than the array has elements, the remaining elements are set to 0.[/color]

          I guess the same holds in C++.


          Regards,

          Niels Dekker
          Deze pagina bestaat niet of is niet meer beschikbaar. Oude XS4ALL-homepages zijn soms nog terug te vinden via webarchieven.

          Comment

          Working...