Create readonly array of data?

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

    Create readonly array of data?

    I want to create a readonly array of data, then a readonly array of a
    structure. This is data I access but I want it protected against
    accidental change. The following is my test code.

    #include "stdafx.h"

    struct LVC
    {
    unsigned short int lo;
    unsigned short int hi;
    };

    void main()
    {
    //This seems to work
    static const unsigned short int LV[4] =
    {0xAC00,
    0xAC1C,
    0xAC38,
    0xAC54 };

    //THIS DOESN'T WORK. COMPILER COMPLAINS
    static const struct LVC[4] = {
    { 0xAC01, 0xAC1B },
    { 0xAC1D, 0xAC37 },
    { 0xAC39, 0xAC53 },
    { 0xAC55, 0xAC6F },
    };

    unsigned short i,j;

    i = LVC[2].lo;
    j = LVC[2].hi;
    }

    I'm using Microsoft Visual C++ Express Edition
    (I'd also like to get rid of that #include "stdafx.h" if
    there's some compiler configuration that will allow me
    to do that.)
  • jacob navia

    #2
    Re: Create readonly array of data?

    Susan Rice a écrit :
    //THIS DOESN'T WORK. COMPILER COMPLAINS
    static const struct LVC[4] = {
    static const struct LVC is the type. You have to give a *name*
    to that array.

    for instance
    static const struct LVC MyTable[4] = {
    etc

    Then you use THAT name:
    i = MyTable[2].lo;
    j = MyTable[2].hi;

    jacob

    P.S.
    it is not void main() but int main(void).
    But that is a detail.

    ---

    A free C compiler for windows

    Comment

    • Default User

      #3
      Re: Create readonly array of data?

      Susan Rice wrote:
      I want to create a readonly array of data, then a readonly array of a
      structure. This is data I access but I want it protected against
      accidental change. The following is my test code.
      >
      #include "stdafx.h"
      See below about this.
      struct LVC
      It's generally prefered by most to reserve all caps for macros.
      {
      unsigned short int lo;
      unsigned short int hi;
      };
      >
      void main()
      This should be int main(void)
      {
      //This seems to work
      static const unsigned short int LV[4] =
      {0xAC00,
      0xAC1C,
      0xAC38,
      0xAC54 };
      >
      //THIS DOESN'T WORK. COMPILER COMPLAINS
      static const struct LVC[4] = {
      LVC is the name of struct type that you created above. What you wanted
      was something like:

      static const struct LVC LVC_array[4] = {
      { 0xAC01, 0xAC1B },
      { 0xAC1D, 0xAC37 },
      { 0xAC39, 0xAC53 },
      { 0xAC55, 0xAC6F },
      };
      >
      unsigned short i,j;
      >
      i = LVC[2].lo;
      j = LVC[2].hi;
      Then change these two names as well.
      }
      >
      I'm using Microsoft Visual C++ Express Edition
      (I'd also like to get rid of that #include "stdafx.h" if
      there's some compiler configuration that will allow me
      to do that.)
      This has to do with pre-compiled headers in VC++. I don't know
      specifically to correct that in Express, but check your project
      settings to remove any dependence. If you can't figure it out, you'll
      need a Microsoft newsgroup.




      Brian

      Comment

      • rhle.freak

        #4
        Re: Create readonly array of data?



        I'm using Microsoft Visual C++ Express Edition
        (I'd also like to get rid of that #include "stdafx.h" if
        there's some compiler configuration that will allow me
        to do that.)
        when u create your project in msvc++

        new project->Win32(win32 console app template is automatically
        selected) ->
        (enter a name for the project)->next->select "empty project"
        option->finish

        then add the header and source files that u need.

        and more simply...
        new project->select "general " option from the Project type window
        ->finish

        //THIS DOESN'T WORK. COMPILER COMPLAINS
        static const struct LVC[4] = {
        { 0xAC01, 0xAC1B },
        u did not name the "template" ..it has been answered above

        regards

        Comment

        • CBFalconer

          #5
          Re: Create readonly array of data?

          "rhle.freak " wrote:
          >
          >I'm using Microsoft Visual C++ Express Edition
          >(I'd also like to get rid of that #include "stdafx.h" if
          >there's some compiler configuration that will allow me
          >to do that.)
          >
          when u create your project in msvc++
          U never posted in this thread. I don't believe he even uses
          c.l.c. If you refrained from snipping attributions it would be
          easier to follow this. In addition msvc++ is system specific and
          off-topic here.

          --
          Merry Christmas, Happy Hanukah, Happy New Year
          Joyeux Noel, Bonne Annee.
          Chuck F (cbfalconer at maineline dot net)
          <http://cbfalconer.home .att.net>


          Comment

          • Richard Heathfield

            #6
            Re: Create readonly array of data?

            CBFalconer said:
            "rhle.freak " wrote:
            >>
            >>I'm using Microsoft Visual C++ Express Edition
            >>(I'd also like to get rid of that #include "stdafx.h" if
            >>there's some compiler configuration that will allow me
            >>to do that.)
            >>
            >when u create your project in msvc++
            >
            U never posted in this thread. I don't believe he even uses
            c.l.c.
            I believe he has done so (although I admit it may have been cp rather than
            clc) - a month or so ago.

            If you refrained from snipping attributions it would be
            easier to follow this. In addition msvc++ is system specific and
            off-topic here.
            Will you not take pity on someone who appears to be trying to coax his
            Microsoft implementation into conforming mode?

            --
            Richard Heathfield
            "Usenet is a strange place" - dmr 29/7/1999

            email: rjh at the above domain, - www.

            Comment

            • Keith Thompson

              #7
              Re: Create readonly array of data?

              "rhle.freak " <rhle.freak@gma il.comwrites:
              [...]
              when u create your project in msvc++
              [...]
              then add the header and source files that u need.
              [...]
              u did not name the "template" ..it has been answered above
              Please don't use silly abbreviations like "u" for "you". It makes
              your articles harder to read, and a lot of people just won't bother.

              And please don't snip attribution lines (lines of the form
              "So-and-so writes:").

              --
              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
              San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
              We must do something. This is something. Therefore, we must do this.

              Comment

              • rhle.freak

                #8
                Re: Create readonly array of data?



                On Jan 1, 7:57 pm, CBFalconer <cbfalco...@yah oo.comwrote:
                "rhle.freak " wrote:
                >
                I'm using Microsoft Visual C++ Express Edition
                (I'd also like to get rid of that #include "stdafx.h" if
                there's some compiler configuration that will allow me
                to do that.)
                >
                when u create your project in msvc++U never posted in this thread. I don't believe he even uses
                c.l.c. If you refrained from snipping attributions it would be
                easier to follow this. In addition msvc++ is system specific and
                off-topic here.
                >
                --
                please do check the earlier thread "stack" which i had posted a few
                days ago! ! regarding using msvc++ ,yes its a specific problem and off
                topic but there is no harm if i am using the same compiler n can help
                someone with something really simple and please do forgive me because
                i am new to using Usenet
                (Google groups to be specific) and my format of posting was wrong,i
                will definitely try to improve on that!!

                Comment

                • CBFalconer

                  #9
                  Re: Create readonly array of data?

                  "rhle.freak " wrote:
                  CBFalconer <cbfalco...@yah oo.comwrote:
                  >"rhle.freak " wrote:
                  >>
                  >>I'm using Microsoft Visual C++ Express Edition
                  >>(I'd also like to get rid of that #include "stdafx.h" if
                  >>there's some compiler configuration that will allow me
                  >>to do that.)
                  >>
                  >>when u create your project in msvc++
                  >>
                  >U never posted in this thread. I don't believe he even uses
                  >c.l.c. If you refrained from snipping attributions it would be
                  >easier to follow this. In addition msvc++ is system specific and
                  >off-topic here.
                  >
                  please do check the earlier thread "stack" which i had posted a few
                  days ago! ! regarding using msvc++ ,yes its a specific problem and off
                  topic but there is no harm if i am using the same compiler n can help
                  someone with something really simple and please do forgive me because
                  i am new to using Usenet
                  (Google groups to be specific) and my format of posting was wrong,i
                  will definitely try to improve on that!!
                  'Another thread' has nothing to do with it. Articles need to stand
                  alone. That is the point of quoting relevant matter. You would be
                  well advised to get a proper newsreader and access usenet directly
                  instead of through the flawed google interface. Also never use
                  silly geekspeak, such as 'u' and 'n' abbreviations. They only
                  serve to annoy and make reading hard, especially for non-English
                  speakers.

                  Just delete the #include <stdafx.hand #include the appropriate
                  standard C includes. The C-library link below will be useful, as
                  will the C99 standard.

                  Some useful references about C:
                  <http://www.ungerhu.com/jxh/clc.welcome.txt >
                  <http://www.eskimo.com/~scs/C-faq/top.html>
                  <http://benpfaff.org/writings/clc/off-topic.html>
                  <http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/(C99)
                  <http://www.dinkumware. com/refxc.html (C-library}
                  <http://gcc.gnu.org/onlinedocs/ (GNU docs)
                  <http://clc-wiki.net (C-info)

                  Some informative links about posting:
                  <http://members.fortune city.com/nnqweb/ (newusers)
                  <http://www.catb.org/~esr/faqs/smart-questions.html>
                  <http://www.caliburn.nl/topposting.html >
                  <http://www.netmeister. org/news/learn2quote.htm l>
                  <http://cfaj.freeshell. org/google/ (taming google)

                  --
                  Merry Christmas, Happy Hanukah, Happy New Year
                  Joyeux Noel, Bonne Annee.
                  Chuck F (cbfalconer at maineline dot net)
                  <http://cbfalconer.home .att.net>


                  Comment

                  • Frodo Baggins

                    #10
                    Re: Create readonly array of data?


                    CBFalconer wrote:
                    "rhle.freak " wrote:
                    CBFalconer <cbfalco...@yah oo.comwrote:
                    "rhle.freak " wrote:
                    <snip>
                    alone. That is the point of quoting relevant matter. You would be
                    well advised to get a proper newsreader and access usenet directly
                    instead of through the flawed google interface. Also never use
                    <snip>

                    How do I access usenet directly?
                    For free ?

                    Regards,
                    Frodo B

                    Comment

                    • CBFalconer

                      #11
                      Re: Create readonly array of data?

                      Frodo Baggins wrote:
                      CBFalconer wrote:
                      >
                      <snip>
                      >
                      >alone. That is the point of quoting relevant matter. You would be
                      >well advised to get a proper newsreader and access usenet directly
                      >instead of through the flawed google interface. Also never use
                      >
                      <snip>
                      >
                      How do I access usenet directly? For free ?
                      Your ISP should provide that. Ask them, and they will also tell
                      you what the servers URL is. This is to be accessed by a news
                      reader, not a browser. If they don't provide a server they are not
                      a proper ISP, but you have the recourse of various free
                      newservers. Others exist, and people may chime in with their URLs.

                      Some free news servers
                      <http://www.teranew.com (free)
                      <http://www.newsfeeds.c om/signup.htm (pay)

                      --
                      Chuck F (cbfalconer at maineline dot net)
                      Available for consulting/temporary embedded and systems.
                      <http://cbfalconer.home .att.net>


                      Comment

                      • Default User

                        #12
                        Re: Create readonly array of data?

                        CBFalconer wrote:

                        Some free news servers
                        <http://www.teranew.com (free)
                        <http://www.teranews.co m/>
                        ^
                        That 's' makes a lot of difference.




                        Brian

                        Comment

                        • Nelu

                          #13
                          Re: Create readonly array of data?

                          CBFalconer wrote:
                          Frodo Baggins wrote:
                          >CBFalconer wrote:
                          >>
                          ><snip>
                          >>
                          >>alone. That is the point of quoting relevant matter. You would be
                          >>well advised to get a proper newsreader and access usenet directly
                          >>instead of through the flawed google interface. Also never use
                          ><snip>
                          >>
                          >How do I access usenet directly? For free ?
                          >
                          Your ISP should provide that. Ask them, and they will also tell
                          you what the servers URL is. This is to be accessed by a news
                          reader, not a browser. If they don't provide a server they are not
                          a proper ISP, but you have the recourse of various free
                          newservers. Others exist, and people may chime in with their URLs.
                          >
                          Some free news servers
                          <http://www.teranew.com (free)
                          <http://www.newsfeeds.c om/signup.htm (pay)
                          >


                          --
                          Ioan - Ciprian Tandau
                          tandau _at_ freeshell _dot_ org (hope it's not too late)
                          (... and that it still works...)

                          Comment

                          • Randy Howard

                            #14
                            Re: Create readonly array of data?

                            On Tue, 2 Jan 2007 06:06:43 -0600, Frodo Baggins wrote
                            (in article <1167739603.495 521.247030@n51g 2000cwc.googleg roups.com>):
                            >
                            CBFalconer wrote:
                            >"rhle.freak " wrote:
                            >>CBFalconer <cbfalco...@yah oo.comwrote:
                            >>>"rhle.frea k" wrote:
                            >
                            <snip>
                            >
                            >alone. That is the point of quoting relevant matter. You would be
                            >well advised to get a proper newsreader and access usenet directly
                            >instead of through the flawed google interface. Also never use
                            >
                            <snip>
                            >
                            How do I access usenet directly?
                            It depends upon your ISP generally.
                            For free ?
                            That depends upon how you define free(). :-)

                            If your ISP bundles it into the price of your normal access fees, you
                            might consider it to be free in that context, as I do.

                            You'll probably need to look on the ISP's website support page (if any)
                            for things like "News server", or "NNTP".

                            It's usually something like:

                            news.ispdomainn ame.com

                            And may or may not require a user id and password for authentication.

                            As for suitable newsreaders, that depends upon your operating system.
                            Some examples of newsreaders are:

                            Windows: Gravity, SuperGravity, Agent, Thunderbird, Outlook Express
                            OS X: Hogwasher, MTNewswatcher, Thunderbird
                            Linux: A ton of them, including Thunderbird, slrn, trn, nn, xrn, and
                            many more.

                            In all almost all cases, the interface provided to Usenet is vastly
                            superior to that of Google.

                            --
                            Randy Howard (2reply remove FOOBAR)
                            "The power of accurate observation is called cynicism by those
                            who have not got it." - George Bernard Shaw





                            Comment

                            • rhle.freak

                              #15
                              Re: Create readonly array of data?



                              On Jan 3, 1:42 am, Nelu <spamah...@gmai l.comwrote:
                              CBFalconer wrote:
                              Frodo Baggins wrote:
                              CBFalconer wrote:
                              >
                              <snip>


                              thank you! i had the Thunderbird client for long ;was looking for a
                              news server .this is just fine!!

                              Comment

                              Working...