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. 900520 - VC6 vs VS 2010

900520 - VC6 vs VS 2010

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++visual-studioquestion
15 Posts 4 Posters 1 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.
  • M Maximilien

    To be frank, I don't know how to interpret it and what it is supposed to be or to do. You got a class containing an array of its own member variable addresses ?

    ilostmyid2 wrote:

    if u mean the offset of them from the beginning of the class instance, we should use offsetof() in such a case which is completely different from this.

    I don't mean anything ... Debugging that code will display something like:

    -A::m_values 0x00e77000 struct A::Info * A::m_values {a=0x00000000 } A::Info [2]

    • [0] {a=0x00000000 } A::Info
    •   a	0x00000000	int \*
      
    • [1] {a=0x00000004 } A::Info
    •   a	0x00000004	int \*
      

    Where m_values[0] is the offset of the first variable and m_values[1] is the offset of the second variable... It is quite an ugly piece of code. Please explain what it is supposed to do .

    Watched code never compiles.

    A Offline
    A Offline
    Albert Holguin
    wrote on last edited by
    #5

    I agree with you, don't see the point in having that array for a number of reasons... its static, so it'll only contain two values regardless of the number of instances of A, and those variables are public anyway, so what's the point of accessing them via a static array?

    1 Reply Last reply
    0
    • M Maximilien

      To be frank, I don't know how to interpret it and what it is supposed to be or to do. You got a class containing an array of its own member variable addresses ?

      ilostmyid2 wrote:

      if u mean the offset of them from the beginning of the class instance, we should use offsetof() in such a case which is completely different from this.

      I don't mean anything ... Debugging that code will display something like:

      -A::m_values 0x00e77000 struct A::Info * A::m_values {a=0x00000000 } A::Info [2]

      • [0] {a=0x00000000 } A::Info
      •   a	0x00000000	int \*
        
      • [1] {a=0x00000004 } A::Info
      •   a	0x00000004	int \*
        

      Where m_values[0] is the offset of the first variable and m_values[1] is the offset of the second variable... It is quite an ugly piece of code. Please explain what it is supposed to do .

      Watched code never compiles.

      I Offline
      I Offline
      ilostmyid2
      wrote on last edited by
      #6

      indeed it's not a code of mine or my friend. this a piece of a large project which my friend uses. they have to port the whole project containing the code from vc6 to vs2010. so, i'm not the writer and i don't know what has been the aim. eg. int is my replacement to CButton for simplification. the structure is not changed though.

      M 1 Reply Last reply
      0
      • I ilostmyid2

        indeed it's not a code of mine or my friend. this a piece of a large project which my friend uses. they have to port the whole project containing the code from vc6 to vs2010. so, i'm not the writer and i don't know what has been the aim. eg. int is my replacement to CButton for simplification. the structure is not changed though.

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #7

        Well, now the code compiles. Just run it and see if the behaviour changes from VC6 to VS2010 ... If it does not work as intended, then either try to understand what it is supposed to do or re-write it.

        Watched code never compiles.

        I 1 Reply Last reply
        0
        • I ilostmyid2

          hi porting a project from VC++ 6 to VS 2010 caused i find a mistake. in the following code i had written:

          #include "StdAfx.h"

          class A
          {
          public:
          struct Info
          {
          int A::*a;
          };
          int a, b;
          static Info m_values[];
          };

          A::Info A::m_values[] = {&a, &b};

          ...

          indeed this is a simplified of what i had. VC 6 doesn't cause error! 1. how it fill m_values? i found that they're filled with 0 and 4! 2. is it essentially a bug of VC against VS 2010? how does it interpret this code? how can it assign m_values with non-instantiated member variables?! does it have a different interpretation when it sees this? i didn't try earlier versions of VS. 3. what's the difference between int A::* and int *?! i know that they're different when we're talking about global functions and member functions. but what about when we're talking about int's? thx

          M Offline
          M Offline
          MicroVirus
          wrote on last edited by
          #8

          From the discussions, it looks like the code is attempting to select 'the same' button (int in the modified example) from every instance of class A, using an index and the Info array. So, as a way of selecting the first or the second button on each instance of A and working with that.

          int whichButton = 1; // or 2
          A* arrayOfA = ... // some value

          for (int i = 0; i < numOfAs; i++)
          {
          CButton& button = arrayOfA[i].*(A::m_values[whichButton]);
          ... // do things with button
          }

          Or something like that. It's probably a good idea to find out what the code does with this. You should search for all references to A::m_values and find out what exactly it's for. Then, think of a proper way of implementing that, or verify that it still works and keep it.

          1 Reply Last reply
          0
          • M Maximilien

            Well, now the code compiles. Just run it and see if the behaviour changes from VC6 to VS2010 ... If it does not work as intended, then either try to understand what it is supposed to do or re-write it.

            Watched code never compiles.

            I Offline
            I Offline
            ilostmyid2
            wrote on last edited by
            #9

            the code compiles only in vc6. in vs2010 i get an error indicating that the array cannot be initialized with &a and &b because they must belong to an instance of A and this is reasonable. i need to know whether it's a bug of vc6 compiler or the vc6 compiler interprets it and makes in sense in a way that vs2010 doesn't.

            M 1 Reply Last reply
            0
            • I ilostmyid2

              the code compiles only in vc6. in vs2010 i get an error indicating that the array cannot be initialized with &a and &b because they must belong to an instance of A and this is reasonable. i need to know whether it's a bug of vc6 compiler or the vc6 compiler interprets it and makes in sense in a way that vs2010 doesn't.

              M Offline
              M Offline
              Maximilien
              wrote on last edited by
              #10

              My first answer fixed the compilation error. In my opinion, this code is crap and should be rewritten/replaced with good meaningful code. Check to see in real life ( in your actual code) if that still works (run) and it is doing what it is supposed to do. Since I really don't know what this code is supposed to do (do you even know what it is supposed to to ?); I cannot help you more. Good luck with that. Max.

              Watched code never compiles.

              I 1 Reply Last reply
              0
              • M Maximilien

                My first answer fixed the compilation error. In my opinion, this code is crap and should be rewritten/replaced with good meaningful code. Check to see in real life ( in your actual code) if that still works (run) and it is doing what it is supposed to do. Since I really don't know what this code is supposed to do (do you even know what it is supposed to to ?); I cannot help you more. Good luck with that. Max.

                Watched code never compiles.

                I Offline
                I Offline
                ilostmyid2
                wrote on last edited by
                #11

                as i mentioned b4, i myself don't know what the code is supposed to do too. i just see that vc6 can realize it and guess the writer has written the code in the way it understand. i just need to know what does the code do so that i may port it to vs2010 to do the same behavior. that's all.

                M 1 Reply Last reply
                0
                • I ilostmyid2

                  as i mentioned b4, i myself don't know what the code is supposed to do too. i just see that vc6 can realize it and guess the writer has written the code in the way it understand. i just need to know what does the code do so that i may port it to vs2010 to do the same behavior. that's all.

                  M Offline
                  M Offline
                  MicroVirus
                  wrote on last edited by
                  #12

                  ilostmyid2 wrote:

                  i myself don't know what the code is supposed to do too

                  ilostmyid2 wrote:

                  i just need to know what does the code do

                  Interesting... So you already know what you have to do; you said it yourself: understand the code. Or, make said modification that allows the code to compile, and it'll probably work exactly like it did in VC6.

                  I 1 Reply Last reply
                  0
                  • M MicroVirus

                    ilostmyid2 wrote:

                    i myself don't know what the code is supposed to do too

                    ilostmyid2 wrote:

                    i just need to know what does the code do

                    Interesting... So you already know what you have to do; you said it yourself: understand the code. Or, make said modification that allows the code to compile, and it'll probably work exactly like it did in VC6.

                    I Offline
                    I Offline
                    ilostmyid2
                    wrote on last edited by
                    #13

                    i created this topic for this, to get help to understand what does the code do!

                    1 Reply Last reply
                    0
                    • I ilostmyid2

                      hi porting a project from VC++ 6 to VS 2010 caused i find a mistake. in the following code i had written:

                      #include "StdAfx.h"

                      class A
                      {
                      public:
                      struct Info
                      {
                      int A::*a;
                      };
                      int a, b;
                      static Info m_values[];
                      };

                      A::Info A::m_values[] = {&a, &b};

                      ...

                      indeed this is a simplified of what i had. VC 6 doesn't cause error! 1. how it fill m_values? i found that they're filled with 0 and 4! 2. is it essentially a bug of VC against VS 2010? how does it interpret this code? how can it assign m_values with non-instantiated member variables?! does it have a different interpretation when it sees this? i didn't try earlier versions of VS. 3. what's the difference between int A::* and int *?! i know that they're different when we're talking about global functions and member functions. but what about when we're talking about int's? thx

                      I Offline
                      I Offline
                      ilostmyid2
                      wrote on last edited by
                      #14

                      let's continue with a completed code. i wonder that it really works and it's not going to be a mistake or bug of the compiler:

                      #include "StdAfx.h"

                      using namespace std;

                      class A
                      {
                      public:
                      struct Info
                      {
                      int A::*a;
                      };
                      int a, b;
                      static Info m_values[];

                      void f();
                      

                      };

                      A::Info A::m_values[] = {&a, &b};

                      void A::f()
                      {
                      int a = this->*(m_values[0].a);
                      int b = this->*(m_values[1].a);
                      cout << "m_values: " << a << ", " << b << endl;
                      }

                      void f()
                      {
                      A a1, a2;
                      a1.a = 10;
                      a1.b = 11;
                      a2.a = 20;
                      a2.b = 21;
                      a1.f();
                      a2.f();
                      }

                      the output is: m_values: 10, 11 m_values: 20, 21 so how does vc6 implements this and what's the equivalent code in vs2010? thx

                      I 1 Reply Last reply
                      0
                      • I ilostmyid2

                        let's continue with a completed code. i wonder that it really works and it's not going to be a mistake or bug of the compiler:

                        #include "StdAfx.h"

                        using namespace std;

                        class A
                        {
                        public:
                        struct Info
                        {
                        int A::*a;
                        };
                        int a, b;
                        static Info m_values[];

                        void f();
                        

                        };

                        A::Info A::m_values[] = {&a, &b};

                        void A::f()
                        {
                        int a = this->*(m_values[0].a);
                        int b = this->*(m_values[1].a);
                        cout << "m_values: " << a << ", " << b << endl;
                        }

                        void f()
                        {
                        A a1, a2;
                        a1.a = 10;
                        a1.b = 11;
                        a2.a = 20;
                        a2.b = 21;
                        a1.f();
                        a2.f();
                        }

                        the output is: m_values: 10, 11 m_values: 20, 21 so how does vc6 implements this and what's the equivalent code in vs2010? thx

                        I Offline
                        I Offline
                        ilostmyid2
                        wrote on last edited by
                        #15

                        ok, i found it at last. it's enough to replace &a and &b in the initialization of m_values with &A::a and &A::b. thank u Maximilien. i couldn't figure it out sooner.

                        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