Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. The Lounge
  4. On the indexing of arrays and other little wonders
Forum Updated to NodeBB v4.3 + New Features

On the indexing of arrays and other little wonders

Scheduled Pinned Locked Moved The Lounge
24 Posts 4 Posters 7.3k Views 3 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.
  • mrjjM mrjj

    And this is why normal people and programmer always talk past each other.
    We start counting at zero and the rest of humanity start with 1 :)

    Btw. I do have this case with PLCs.
    Their (internal) lists start a 1 and so when I transfer from c/c++ i have to manage that
    and hence I do not use index 0 in the c++ code as not to go crazy with +/- 1 all over.

    on c++ is also [X] on PLC and

    not [X+1]

    [Forked from http://forum.qt.io/topic/68625/qlist-index ~kshegunov]

    Joel BodenmannJ Offline
    Joel BodenmannJ Offline
    Joel Bodenmann
    wrote on last edited by Joel Bodenmann
    #3

    @mrjj said:

    And this is why normal people and programmer always talk past each other.
    We start counting at zero and the rest of humanity start with 1 :)

    Actually, my hardware design professor (FPGAs and stuff) can't stand it if I/we start to enumerate with 0 instead of 1. Yes sure, one can now pull the argument whether people doing hardware design using tools like VHDL and Verilog are actually programmers but... do they count as "normal people"? :p
    It's just funny to see that a very decent engineer/professor doesn't like enumeration to start with zero.
    Next time I'll have that discussion with him (which is surprisingly often), I'll pull the argument that @kshegunov stated: It's the offset of the element :p

    Maybe we get too off-topic now.

    Industrial process automation software: https://simulton.com
    Embedded Graphics & GUI library: https://ugfx.io

    mrjjM kshegunovK 2 Replies Last reply
    0
    • Joel BodenmannJ Joel Bodenmann

      @mrjj said:

      And this is why normal people and programmer always talk past each other.
      We start counting at zero and the rest of humanity start with 1 :)

      Actually, my hardware design professor (FPGAs and stuff) can't stand it if I/we start to enumerate with 0 instead of 1. Yes sure, one can now pull the argument whether people doing hardware design using tools like VHDL and Verilog are actually programmers but... do they count as "normal people"? :p
      It's just funny to see that a very decent engineer/professor doesn't like enumeration to start with zero.
      Next time I'll have that discussion with him (which is surprisingly often), I'll pull the argument that @kshegunov stated: It's the offset of the element :p

      Maybe we get too off-topic now.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @Joel-Bodenmann

      • Maybe we get too off-topic now

      the_T 1 Reply Last reply
      3
      • mrjjM mrjj

        @Joel-Bodenmann

        • Maybe we get too off-topic now

        the_T Offline
        the_T Offline
        the_
        wrote on last edited by
        #5

        @mrjj
        Can't you just move the topic to another sub forum where its not off topic anymore? ;)

        -- No support in PM --

        Joel BodenmannJ mrjjM 2 Replies Last reply
        0
        • the_T the_

          @mrjj
          Can't you just move the topic to another sub forum where its not off topic anymore? ;)

          Joel BodenmannJ Offline
          Joel BodenmannJ Offline
          Joel Bodenmann
          wrote on last edited by Joel Bodenmann
          #6

          That would probably be rather rude for the OP :p

          Industrial process automation software: https://simulton.com
          Embedded Graphics & GUI library: https://ugfx.io

          1 Reply Last reply
          0
          • the_T the_

            @mrjj
            Can't you just move the topic to another sub forum where its not off topic anymore? ;)

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #7

            @the_
            well i could - but is it that off ?
            Still about the wonders of zero index with some extra ;)

            1 Reply Last reply
            0
            • Joel BodenmannJ Joel Bodenmann

              @mrjj said:

              And this is why normal people and programmer always talk past each other.
              We start counting at zero and the rest of humanity start with 1 :)

              Actually, my hardware design professor (FPGAs and stuff) can't stand it if I/we start to enumerate with 0 instead of 1. Yes sure, one can now pull the argument whether people doing hardware design using tools like VHDL and Verilog are actually programmers but... do they count as "normal people"? :p
              It's just funny to see that a very decent engineer/professor doesn't like enumeration to start with zero.
              Next time I'll have that discussion with him (which is surprisingly often), I'll pull the argument that @kshegunov stated: It's the offset of the element :p

              Maybe we get too off-topic now.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #8

              @Joel-Bodenmann said:

              It's just funny to see that a very decent engineer/professor doesn't like enumeration to start with zero.

              Everyone has the right to have no taste ...

              I'll pull the argument that @kshegunov stated: It's the offset of the element :p

              I thought this was common knowledge.

              How is this:

              int x[5];
              x[2] = 0;
              

              different from:

              *(x + 2) = 0;
              

              PS: Except for the extreme ugliness of the latter that is ... :)

              Read and abide by the Qt Code of Conduct

              Joel BodenmannJ 1 Reply Last reply
              0
              • kshegunovK kshegunov

                @Joel-Bodenmann said:

                It's just funny to see that a very decent engineer/professor doesn't like enumeration to start with zero.

                Everyone has the right to have no taste ...

                I'll pull the argument that @kshegunov stated: It's the offset of the element :p

                I thought this was common knowledge.

                How is this:

                int x[5];
                x[2] = 0;
                

                different from:

                *(x + 2) = 0;
                

                PS: Except for the extreme ugliness of the latter that is ... :)

                Joel BodenmannJ Offline
                Joel BodenmannJ Offline
                Joel Bodenmann
                wrote on last edited by Joel Bodenmann
                #9

                @kshegunov This is probably the point where I can dump this one...

                #include <iostream>
                #include <string>
                
                int main()
                {
                	std::string a[] = {"Hello", "World"};
                	
                	std::cout << 0[a] << std::endl;
                	std::cout << 1[a] << std::endl;
                	
                	return 0;
                }
                

                This proves that operator[] is really nothing but an offset operator (well, one can overload it for classes, yes....).

                Industrial process automation software: https://simulton.com
                Embedded Graphics & GUI library: https://ugfx.io

                kshegunovK 1 Reply Last reply
                0
                • Joel BodenmannJ Joel Bodenmann

                  @kshegunov This is probably the point where I can dump this one...

                  #include <iostream>
                  #include <string>
                  
                  int main()
                  {
                  	std::string a[] = {"Hello", "World"};
                  	
                  	std::cout << 0[a] << std::endl;
                  	std::cout << 1[a] << std::endl;
                  	
                  	return 0;
                  }
                  

                  This proves that operator[] is really nothing but an offset operator (well, one can overload it for classes, yes....).

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #10

                  @Joel-Bodenmann

                  Man, this:

                  std::cout << 0[a] << std::endl;
                  

                  shouldn't work even on Friday ...

                  By the way, the proper way to unnecessarily make things look unfathomable is to use fully qualified access:

                  std::cout << a.operator[] (0) << std::endl;
                  

                  :)

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  0
                  • Joel BodenmannJ Offline
                    Joel BodenmannJ Offline
                    Joel Bodenmann
                    wrote on last edited by Joel Bodenmann
                    #11

                    @kshegunov said:

                    By the way, the proper way to unnecessarily make things look unfathomable is to use fully qualified access:

                    std::cout << a.operator[] (0) << std::endl;
                    

                    Well, that won't work with plain arrays ;)
                    Also you can't annoy C people with that.

                    Industrial process automation software: https://simulton.com
                    Embedded Graphics & GUI library: https://ugfx.io

                    kshegunovK 1 Reply Last reply
                    0
                    • Joel BodenmannJ Joel Bodenmann

                      @kshegunov said:

                      By the way, the proper way to unnecessarily make things look unfathomable is to use fully qualified access:

                      std::cout << a.operator[] (0) << std::endl;
                      

                      Well, that won't work with plain arrays ;)
                      Also you can't annoy C people with that.

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by kshegunov
                      #12

                      @Joel-Bodenmann
                      You youngsters and your requirements ... plain arrays are plain, they need no stinkin' (custom) operators in the first place ... :D

                      Also you can't annoy C people with that.

                      With this I agree completely, but they can still annoy you by naming their variables new, like this:

                      char new[5]; //< This always makes my day
                      

                      Read and abide by the Qt Code of Conduct

                      the_T Joel BodenmannJ 2 Replies Last reply
                      0
                      • kshegunovK kshegunov

                        @Joel-Bodenmann
                        You youngsters and your requirements ... plain arrays are plain, they need no stinkin' (custom) operators in the first place ... :D

                        Also you can't annoy C people with that.

                        With this I agree completely, but they can still annoy you by naming their variables new, like this:

                        char new[5]; //< This always makes my day
                        
                        the_T Offline
                        the_T Offline
                        the_
                        wrote on last edited by
                        #13
                        char new[5]; //< This always makes my day
                        

                        Thats as hard as

                        public class if {
                        
                        } 
                        

                        ;)

                        -- No support in PM --

                        kshegunovK 1 Reply Last reply
                        0
                        • kshegunovK kshegunov

                          @Joel-Bodenmann
                          You youngsters and your requirements ... plain arrays are plain, they need no stinkin' (custom) operators in the first place ... :D

                          Also you can't annoy C people with that.

                          With this I agree completely, but they can still annoy you by naming their variables new, like this:

                          char new[5]; //< This always makes my day
                          
                          Joel BodenmannJ Offline
                          Joel BodenmannJ Offline
                          Joel Bodenmann
                          wrote on last edited by Joel Bodenmann
                          #14

                          @kshegunov
                          What about #define float int? :p
                          If you hide stuff like this: #define if(x) you can truly fuck someone's day.

                          However, the most evil one might be this: #define struct union.

                          Industrial process automation software: https://simulton.com
                          Embedded Graphics & GUI library: https://ugfx.io

                          the_T 1 Reply Last reply
                          0
                          • Joel BodenmannJ Joel Bodenmann

                            @kshegunov
                            What about #define float int? :p
                            If you hide stuff like this: #define if(x) you can truly fuck someone's day.

                            However, the most evil one might be this: #define struct union.

                            the_T Offline
                            the_T Offline
                            the_
                            wrote on last edited by
                            #15

                            @Joel-Bodenmann

                            Or try to

                            #define true false
                            

                            in a global headerfile in a large project ;)

                            -- No support in PM --

                            1 Reply Last reply
                            1
                            • the_T the_
                              char new[5]; //< This always makes my day
                              

                              Thats as hard as

                              public class if {
                              
                              } 
                              

                              ;)

                              kshegunovK Offline
                              kshegunovK Offline
                              kshegunov
                              Moderators
                              wrote on last edited by
                              #16

                              @the_ said:

                              public class if {
                              
                              } 
                              

                              Ouch! There's tons of weird stuff a C dev might do, like:

                              struct class object;
                              

                              @Joel-Bodenmann

                              Aha! We are bringing the heavy artillery, aren't we?

                              Since the preprocessor is not part of the language, and it's run before anything else ... and it's just string substitution, you can make very ugly stuff, like:

                              #define true 0
                              #define false 1
                              

                              Read and abide by the Qt Code of Conduct

                              Joel BodenmannJ the_T 2 Replies Last reply
                              0
                              • kshegunovK kshegunov

                                @the_ said:

                                public class if {
                                
                                } 
                                

                                Ouch! There's tons of weird stuff a C dev might do, like:

                                struct class object;
                                

                                @Joel-Bodenmann

                                Aha! We are bringing the heavy artillery, aren't we?

                                Since the preprocessor is not part of the language, and it's run before anything else ... and it's just string substitution, you can make very ugly stuff, like:

                                #define true 0
                                #define false 1
                                
                                Joel BodenmannJ Offline
                                Joel BodenmannJ Offline
                                Joel Bodenmann
                                wrote on last edited by Joel Bodenmann
                                #17

                                @kshegunov

                                Aha! We are bringing the heavy artillery, aren't we?

                                No Sir, this is the heavy artillery:

                                #define if(x) if((__LINE__ % > 500)^(x))
                                

                                Everything works well as long as the source doesn't grow larger than 500 lines.

                                And if you want to keep people from fucking with your sources/algorithms, you can carefully write a program with this:

                                #define if(x) if((__LINE__ % 5==0)^(x))
                                

                                If done right, your stuff will work fine for as long as nobody adds or removes a line.

                                </topic>

                                Industrial process automation software: https://simulton.com
                                Embedded Graphics & GUI library: https://ugfx.io

                                kshegunovK 1 Reply Last reply
                                0
                                • Joel BodenmannJ Joel Bodenmann

                                  @kshegunov

                                  Aha! We are bringing the heavy artillery, aren't we?

                                  No Sir, this is the heavy artillery:

                                  #define if(x) if((__LINE__ % > 500)^(x))
                                  

                                  Everything works well as long as the source doesn't grow larger than 500 lines.

                                  And if you want to keep people from fucking with your sources/algorithms, you can carefully write a program with this:

                                  #define if(x) if((__LINE__ % 5==0)^(x))
                                  

                                  If done right, your stuff will work fine for as long as nobody adds or removes a line.

                                  </topic>

                                  kshegunovK Offline
                                  kshegunovK Offline
                                  kshegunov
                                  Moderators
                                  wrote on last edited by
                                  #18

                                  @Joel-Bodenmann

                                  This is (somewhat) tractable. My greatest clash with the preprocessor was when I was served with a "class" that defined a 256 item color table by means of members for each of 256 colors ... the properties, getters and setters were naturally defined through preprocessor macros. It was one of the low points of my life ... :)

                                  Read and abide by the Qt Code of Conduct

                                  1 Reply Last reply
                                  0
                                  • kshegunovK kshegunov

                                    @the_ said:

                                    public class if {
                                    
                                    } 
                                    

                                    Ouch! There's tons of weird stuff a C dev might do, like:

                                    struct class object;
                                    

                                    @Joel-Bodenmann

                                    Aha! We are bringing the heavy artillery, aren't we?

                                    Since the preprocessor is not part of the language, and it's run before anything else ... and it's just string substitution, you can make very ugly stuff, like:

                                    #define true 0
                                    #define false 1
                                    
                                    the_T Offline
                                    the_T Offline
                                    the_
                                    wrote on last edited by
                                    #19

                                    @kshegunov said:

                                    @the_ said:

                                    public class if {
                                    
                                    } 
                                    

                                    Ouch! There's tons of weird stuff a C dev might do, like:

                                    I think it was Java code where i found this crap :)

                                    -- No support in PM --

                                    kshegunovK Joel BodenmannJ 2 Replies Last reply
                                    0
                                    • the_T the_

                                      @kshegunov said:

                                      @the_ said:

                                      public class if {
                                      
                                      } 
                                      

                                      Ouch! There's tons of weird stuff a C dev might do, like:

                                      I think it was Java code where i found this crap :)

                                      kshegunovK Offline
                                      kshegunovK Offline
                                      kshegunov
                                      Moderators
                                      wrote on last edited by
                                      #20

                                      @the_

                                      I think it was Java code where i found this crap

                                      Well, Java is C++'s little sister, too bad her genes got screwed up and she turned out a freak ;)

                                      Read and abide by the Qt Code of Conduct

                                      1 Reply Last reply
                                      0
                                      • the_T the_

                                        @kshegunov said:

                                        @the_ said:

                                        public class if {
                                        
                                        } 
                                        

                                        Ouch! There's tons of weird stuff a C dev might do, like:

                                        I think it was Java code where i found this crap :)

                                        Joel BodenmannJ Offline
                                        Joel BodenmannJ Offline
                                        Joel Bodenmann
                                        wrote on last edited by Joel Bodenmann
                                        #21

                                        @kshegunov
                                        You might like my embedded graphics/GUI library then. Everything that can be done with preprocessor macros is done using preprocessor macros:

                                        https://bitbucket.org/Tectu/ugfx/src/fb100bcc25225cfad0bab5d40bef1db703e9670a/src/gdisp/gdisp_colors.h?at=master&fileviewer=file-view-default
                                        https://bitbucket.org/Tectu/ugfx/src/fb100bcc25225cfad0bab5d40bef1db703e9670a/src/gdisp/gdisp_driver.h?at=master&fileviewer=file-view-default#gdisp_driver.h-812

                                        If you keep browsing the sources you will find other goodies :)

                                        Industrial process automation software: https://simulton.com
                                        Embedded Graphics & GUI library: https://ugfx.io

                                        kshegunovK 1 Reply Last reply
                                        0
                                        • Joel BodenmannJ Joel Bodenmann

                                          @kshegunov
                                          You might like my embedded graphics/GUI library then. Everything that can be done with preprocessor macros is done using preprocessor macros:

                                          https://bitbucket.org/Tectu/ugfx/src/fb100bcc25225cfad0bab5d40bef1db703e9670a/src/gdisp/gdisp_colors.h?at=master&fileviewer=file-view-default
                                          https://bitbucket.org/Tectu/ugfx/src/fb100bcc25225cfad0bab5d40bef1db703e9670a/src/gdisp/gdisp_driver.h?at=master&fileviewer=file-view-default#gdisp_driver.h-812

                                          If you keep browsing the sources you will find other goodies :)

                                          kshegunovK Offline
                                          kshegunovK Offline
                                          kshegunov
                                          Moderators
                                          wrote on last edited by
                                          #22

                                          @Joel-Bodenmann
                                          Right ... because my life doesn't suck enough and I would like to suffer more? I'm with @Wieland on that preprocessor magic - I avoid as the devil avoids incense ... there's a whole battery of cheat-sheets for dealing with that ugly monster ...

                                          Read and abide by the Qt Code of Conduct

                                          Joel BodenmannJ 1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved