Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to declare a one based array ?

how to declare a one based array ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structurestutorialquestion
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    timbk
    wrote on last edited by
    #1

    hello, is there any way to declare an indexed array in base one on VC++? thanks.

    L C T 3 Replies Last reply
    0
    • T timbk

      hello, is there any way to declare an indexed array in base one on VC++? thanks.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      AFAIK no. Either make the array one element bigger and ignore element zero; or subtract one from every index. :)

      Luc Pattyn


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      1 Reply Last reply
      0
      • T timbk

        hello, is there any way to declare an indexed array in base one on VC++? thanks.

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        timbk wrote:

        hello, is there any way to declare an indexed array in base one on VC++? thanks.

        You can even use ten-based array: just remember to subract 10 to the index before using it inside the [] operator... :rolleyes: [added] Hi, Mr.Univoter. Don't you like 10-based arrays, do you? :-D [/added]

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        modified on Wednesday, November 11, 2009 3:04 AM

        T 1 Reply Last reply
        0
        • C CPallini

          timbk wrote:

          hello, is there any way to declare an indexed array in base one on VC++? thanks.

          You can even use ten-based array: just remember to subract 10 to the index before using it inside the [] operator... :rolleyes: [added] Hi, Mr.Univoter. Don't you like 10-based arrays, do you? :-D [/added]

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          modified on Wednesday, November 11, 2009 3:04 AM

          T Offline
          T Offline
          timbk
          wrote on last edited by
          #4

          thanks, how can i do to declare a ten based array?

          C 1 Reply Last reply
          0
          • T timbk

            hello, is there any way to declare an indexed array in base one on VC++? thanks.

            T Offline
            T Offline
            Tim Craig
            wrote on last edited by
            #5

            As they said, no, but you could write your own 1 based array class in C++ and overload the [] operator and whatever else is necessary to do the index adjustment for you. X|

            You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

            T 1 Reply Last reply
            0
            • T timbk

              thanks, how can i do to declare a ten based array?

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              timbk wrote:

              thanks, how can i do to declare a ten based array?

              Do you understand irony music, Yoko? :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              T 1 Reply Last reply
              0
              • T Tim Craig

                As they said, no, but you could write your own 1 based array class in C++ and overload the [] operator and whatever else is necessary to do the index adjustment for you. X|

                You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

                T Offline
                T Offline
                timbk
                wrote on last edited by
                #7

                thanks, well i was trying to make the app more easy to follow, because 0 based arrays are not so intuitive, we starts count in one, i think that the easy way is make the array one element bigger but when you have many arrays is a waste of memo, so i would try with your seggest.

                T C 2 Replies Last reply
                0
                • C CPallini

                  timbk wrote:

                  thanks, how can i do to declare a ten based array?

                  Do you understand irony music, Yoko? :-D

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  T Offline
                  T Offline
                  timbk
                  wrote on last edited by
                  #8

                  ohh, sorry i'm learning english and VC++, and i don't study " how to understand jokes".

                  C 1 Reply Last reply
                  0
                  • T timbk

                    thanks, well i was trying to make the app more easy to follow, because 0 based arrays are not so intuitive, we starts count in one, i think that the easy way is make the array one element bigger but when you have many arrays is a waste of memo, so i would try with your seggest.

                    T Offline
                    T Offline
                    Tim Craig
                    wrote on last edited by
                    #9

                    If you search around, you probably can find example code. I think I once saw it as an example in a C++ book.

                    You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

                    1 Reply Last reply
                    0
                    • T timbk

                      ohh, sorry i'm learning english and VC++, and i don't study " how to understand jokes".

                      C Offline
                      C Offline
                      CPallini
                      wrote on last edited by
                      #10

                      I'm sorry for you. C/C++ arrays are zero based. While there's nothing wrong in liking better one-based arrays, it is wiser remaining stuck with zero-based ones, because:

                      • You need extra work to make your arrays alive (extra work is generally bad)
                      • Most people use the opposite convention: that means you have to adapt your data to any time you've to deal with other people code, like libraries, etc..

                      Neverthless, there are few examples of consistently used one-based arrays, for instance, all "Numerical Recipes" book source code uses it (the authors simply ignore array item 0). Like all 'alien' conventions it's a bit difficult to grasp immediately, but after some experience with, becomes 'natural'. :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      1 Reply Last reply
                      0
                      • T timbk

                        thanks, well i was trying to make the app more easy to follow, because 0 based arrays are not so intuitive, we starts count in one, i think that the easy way is make the array one element bigger but when you have many arrays is a waste of memo, so i would try with your seggest.

                        C Offline
                        C Offline
                        Chris Losinger
                        wrote on last edited by
                        #11

                        timbk wrote:

                        i was trying to make the app more easy to follow, because 0 based arrays are not so intuitive

                        you will confuse any C/C++ programmer who has to maintain the code, if you start doing things like that.

                        image processing toolkits | batch image processing

                        T 1 Reply Last reply
                        0
                        • C Chris Losinger

                          timbk wrote:

                          i was trying to make the app more easy to follow, because 0 based arrays are not so intuitive

                          you will confuse any C/C++ programmer who has to maintain the code, if you start doing things like that.

                          image processing toolkits | batch image processing

                          T Offline
                          T Offline
                          Tim Craig
                          wrote on last edited by
                          #12

                          How is that any different than most of the code I had to maintain in my career? :laugh:

                          You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups