C++ Struct throws Memory DumpWhy compiler doesn't allow std::string inside union?Is a Union Member's Destructor CalledWhen should you use a class vs a struct in C++?What are the differences between a pointer variable and a reference variable in C++?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListDifference between 'struct' and 'typedef struct' in C++?What is the effect of extern “C” in C++?What is the “-->” operator in C++?Easiest way to convert int to string in C++C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why is reading lines from stdin much slower in C++ than Python?

Why are flying carpets banned while flying brooms are not?

"Je suis petite, moi?", purpose of the "moi"?

What image should I install on VirtualBox for practising dev ops

Why is Google approaching my VPS machine?

Did Hitler say this quote about homeschooling?

How important are the Author's mood and feelings for writing a story?

Do pedestrians imitate auto traffic?

What could make large expeditions ineffective for exploring territory full of dangers and valuable resources?

Pauli exclusion principle - black holes

Align the contents of a numerical matrix when you have minus signs

Could a US citizen born through "birth tourism" become President?

Improving an O(N^2) function (all entities iterating over all other entities)

What's a German word for »Sandbagger«?

Why does a tetrahedral molecule like methane have a dipole moment of zero?

Should I have shared a document with a former employee?

"This used to be my phone number"

Applying for jobs with an obvious scar

What is the name for the average of the largest and the smallest values in a given data set?

Why can't I hear fret buzz through the amp?

How to belay quickly ascending top-rope climbers?

Is it possible to have a career in SciComp without contributing to arms research?

Who or what determines if a curse is valid or not?

Difference between class and struct in with regards to padding and inheritance

Why isn't a binary file shown as 0s and 1s?



C++ Struct throws Memory Dump


Why compiler doesn't allow std::string inside union?Is a Union Member's Destructor CalledWhen should you use a class vs a struct in C++?What are the differences between a pointer variable and a reference variable in C++?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListDifference between 'struct' and 'typedef struct' in C++?What is the effect of extern “C” in C++?What is the “-->” operator in C++?Easiest way to convert int to string in C++C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why is reading lines from stdin much slower in C++ than Python?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-2















i am the "proud" heir of an old VC++ DLL and try to understand a problem with it. My predecessor used some union/struct constructions for dataprocessing. Now i debugged it to a point he put the data in the struct, but the whole app crashes, printing a memory dump and no try-catch works.



A small CodeExample.



MyCode.h:



union

struct
double _dm;
;
struct
double _dm;
bool _links;
;
struct
double _dm;
double _dummy;
double _angle;
;
struct
double _dm;
double _angle;
double _dummy1;
string _name;
string _descr;
double _param_d1, _param_d2, _param_d5;
double _dummy2;
string _dummy3;
int _epuzae;
int _param_i2;
string _sob, _snr2, _param_s3, _param_s4;
void *_data;
;
struct
void *_data;
;



MyCode.cpp



... Rest of the method...
_dm = 100; // Will be set
_angle = 0; // Will be set
_dummy1 = 0; // Will be set
_name = "Unittest"; // Here it crashes the whole app
_descr = "This is a test";
_param_d1 = 1;
_param_d2 = 2;
_param_d5 = 5;
_dummy2 = 0;
_dummy3 = "";
_epuzae = 99;
_param_i2 = 101;
...


Is there a method to test what struct constructor is called or what i am doing wrong here?



Best regards



Lord_Pinhead










share|improve this question

















  • 1





    Please add a minimal reproducible example. A union with a non trivial type in it (std::string in this case) is not trivial and requires a bunch of extra work on your part. You basically need to implement a tagged union. See: stackoverflow.com/questions/40106941/…

    – NathanOliver
    Mar 18 at 15:09











  • what is string is it std::string?

    – rafael gonzalez
    Mar 18 at 15:14











  • How is this union initialized?

    – Michael Kenzel
    Mar 18 at 15:16











  • There are a huge number of ways a person can go horribly wrong with a union. We need to see how the union is being used to see how (or if) it is being abused.

    – user4581301
    Mar 18 at 15:17












  • Rafael, yes it is a std::string Nathan I will try a tagged version thanks. I never used structs in c++, I have classes for that. Michael I kid you not, the second part is everything, no initialization. In Prod it somehow works. The guy was no programmer, he learned it with this app, so that is all I have for now. I make a unittest tomorrow and post a status.

    – Lord_Pinhead
    Mar 18 at 15:31

















-2















i am the "proud" heir of an old VC++ DLL and try to understand a problem with it. My predecessor used some union/struct constructions for dataprocessing. Now i debugged it to a point he put the data in the struct, but the whole app crashes, printing a memory dump and no try-catch works.



A small CodeExample.



MyCode.h:



union

struct
double _dm;
;
struct
double _dm;
bool _links;
;
struct
double _dm;
double _dummy;
double _angle;
;
struct
double _dm;
double _angle;
double _dummy1;
string _name;
string _descr;
double _param_d1, _param_d2, _param_d5;
double _dummy2;
string _dummy3;
int _epuzae;
int _param_i2;
string _sob, _snr2, _param_s3, _param_s4;
void *_data;
;
struct
void *_data;
;



MyCode.cpp



... Rest of the method...
_dm = 100; // Will be set
_angle = 0; // Will be set
_dummy1 = 0; // Will be set
_name = "Unittest"; // Here it crashes the whole app
_descr = "This is a test";
_param_d1 = 1;
_param_d2 = 2;
_param_d5 = 5;
_dummy2 = 0;
_dummy3 = "";
_epuzae = 99;
_param_i2 = 101;
...


Is there a method to test what struct constructor is called or what i am doing wrong here?



Best regards



Lord_Pinhead










share|improve this question

















  • 1





    Please add a minimal reproducible example. A union with a non trivial type in it (std::string in this case) is not trivial and requires a bunch of extra work on your part. You basically need to implement a tagged union. See: stackoverflow.com/questions/40106941/…

    – NathanOliver
    Mar 18 at 15:09











  • what is string is it std::string?

    – rafael gonzalez
    Mar 18 at 15:14











  • How is this union initialized?

    – Michael Kenzel
    Mar 18 at 15:16











  • There are a huge number of ways a person can go horribly wrong with a union. We need to see how the union is being used to see how (or if) it is being abused.

    – user4581301
    Mar 18 at 15:17












  • Rafael, yes it is a std::string Nathan I will try a tagged version thanks. I never used structs in c++, I have classes for that. Michael I kid you not, the second part is everything, no initialization. In Prod it somehow works. The guy was no programmer, he learned it with this app, so that is all I have for now. I make a unittest tomorrow and post a status.

    – Lord_Pinhead
    Mar 18 at 15:31













-2












-2








-2








i am the "proud" heir of an old VC++ DLL and try to understand a problem with it. My predecessor used some union/struct constructions for dataprocessing. Now i debugged it to a point he put the data in the struct, but the whole app crashes, printing a memory dump and no try-catch works.



A small CodeExample.



MyCode.h:



union

struct
double _dm;
;
struct
double _dm;
bool _links;
;
struct
double _dm;
double _dummy;
double _angle;
;
struct
double _dm;
double _angle;
double _dummy1;
string _name;
string _descr;
double _param_d1, _param_d2, _param_d5;
double _dummy2;
string _dummy3;
int _epuzae;
int _param_i2;
string _sob, _snr2, _param_s3, _param_s4;
void *_data;
;
struct
void *_data;
;



MyCode.cpp



... Rest of the method...
_dm = 100; // Will be set
_angle = 0; // Will be set
_dummy1 = 0; // Will be set
_name = "Unittest"; // Here it crashes the whole app
_descr = "This is a test";
_param_d1 = 1;
_param_d2 = 2;
_param_d5 = 5;
_dummy2 = 0;
_dummy3 = "";
_epuzae = 99;
_param_i2 = 101;
...


Is there a method to test what struct constructor is called or what i am doing wrong here?



Best regards



Lord_Pinhead










share|improve this question














i am the "proud" heir of an old VC++ DLL and try to understand a problem with it. My predecessor used some union/struct constructions for dataprocessing. Now i debugged it to a point he put the data in the struct, but the whole app crashes, printing a memory dump and no try-catch works.



A small CodeExample.



MyCode.h:



union

struct
double _dm;
;
struct
double _dm;
bool _links;
;
struct
double _dm;
double _dummy;
double _angle;
;
struct
double _dm;
double _angle;
double _dummy1;
string _name;
string _descr;
double _param_d1, _param_d2, _param_d5;
double _dummy2;
string _dummy3;
int _epuzae;
int _param_i2;
string _sob, _snr2, _param_s3, _param_s4;
void *_data;
;
struct
void *_data;
;



MyCode.cpp



... Rest of the method...
_dm = 100; // Will be set
_angle = 0; // Will be set
_dummy1 = 0; // Will be set
_name = "Unittest"; // Here it crashes the whole app
_descr = "This is a test";
_param_d1 = 1;
_param_d2 = 2;
_param_d5 = 5;
_dummy2 = 0;
_dummy3 = "";
_epuzae = 99;
_param_i2 = 101;
...


Is there a method to test what struct constructor is called or what i am doing wrong here?



Best regards



Lord_Pinhead







c++ visual-c++ visual-studio-2017






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 18 at 15:06









Lord_PinheadLord_Pinhead

508 bronze badges




508 bronze badges







  • 1





    Please add a minimal reproducible example. A union with a non trivial type in it (std::string in this case) is not trivial and requires a bunch of extra work on your part. You basically need to implement a tagged union. See: stackoverflow.com/questions/40106941/…

    – NathanOliver
    Mar 18 at 15:09











  • what is string is it std::string?

    – rafael gonzalez
    Mar 18 at 15:14











  • How is this union initialized?

    – Michael Kenzel
    Mar 18 at 15:16











  • There are a huge number of ways a person can go horribly wrong with a union. We need to see how the union is being used to see how (or if) it is being abused.

    – user4581301
    Mar 18 at 15:17












  • Rafael, yes it is a std::string Nathan I will try a tagged version thanks. I never used structs in c++, I have classes for that. Michael I kid you not, the second part is everything, no initialization. In Prod it somehow works. The guy was no programmer, he learned it with this app, so that is all I have for now. I make a unittest tomorrow and post a status.

    – Lord_Pinhead
    Mar 18 at 15:31












  • 1





    Please add a minimal reproducible example. A union with a non trivial type in it (std::string in this case) is not trivial and requires a bunch of extra work on your part. You basically need to implement a tagged union. See: stackoverflow.com/questions/40106941/…

    – NathanOliver
    Mar 18 at 15:09











  • what is string is it std::string?

    – rafael gonzalez
    Mar 18 at 15:14











  • How is this union initialized?

    – Michael Kenzel
    Mar 18 at 15:16











  • There are a huge number of ways a person can go horribly wrong with a union. We need to see how the union is being used to see how (or if) it is being abused.

    – user4581301
    Mar 18 at 15:17












  • Rafael, yes it is a std::string Nathan I will try a tagged version thanks. I never used structs in c++, I have classes for that. Michael I kid you not, the second part is everything, no initialization. In Prod it somehow works. The guy was no programmer, he learned it with this app, so that is all I have for now. I make a unittest tomorrow and post a status.

    – Lord_Pinhead
    Mar 18 at 15:31







1




1





Please add a minimal reproducible example. A union with a non trivial type in it (std::string in this case) is not trivial and requires a bunch of extra work on your part. You basically need to implement a tagged union. See: stackoverflow.com/questions/40106941/…

– NathanOliver
Mar 18 at 15:09





Please add a minimal reproducible example. A union with a non trivial type in it (std::string in this case) is not trivial and requires a bunch of extra work on your part. You basically need to implement a tagged union. See: stackoverflow.com/questions/40106941/…

– NathanOliver
Mar 18 at 15:09













what is string is it std::string?

– rafael gonzalez
Mar 18 at 15:14





what is string is it std::string?

– rafael gonzalez
Mar 18 at 15:14













How is this union initialized?

– Michael Kenzel
Mar 18 at 15:16





How is this union initialized?

– Michael Kenzel
Mar 18 at 15:16













There are a huge number of ways a person can go horribly wrong with a union. We need to see how the union is being used to see how (or if) it is being abused.

– user4581301
Mar 18 at 15:17






There are a huge number of ways a person can go horribly wrong with a union. We need to see how the union is being used to see how (or if) it is being abused.

– user4581301
Mar 18 at 15:17














Rafael, yes it is a std::string Nathan I will try a tagged version thanks. I never used structs in c++, I have classes for that. Michael I kid you not, the second part is everything, no initialization. In Prod it somehow works. The guy was no programmer, he learned it with this app, so that is all I have for now. I make a unittest tomorrow and post a status.

– Lord_Pinhead
Mar 18 at 15:31





Rafael, yes it is a std::string Nathan I will try a tagged version thanks. I never used structs in c++, I have classes for that. Michael I kid you not, the second part is everything, no initialization. In Prod it somehow works. The guy was no programmer, he learned it with this app, so that is all I have for now. I make a unittest tomorrow and post a status.

– Lord_Pinhead
Mar 18 at 15:31












1 Answer
1






active

oldest

votes


















0














After to much trouble and helpfull links why not use struct with strings, i refactored it yesterday to a class, what runs like a charme:



 class DPic 
public:
DPic();
~DPic();

double DM;
double Angle;
std::string Name;
std::string Descr;
double Param_d1, Param_d2, Param_d5;
int Epuzae;
int Param_i2;
std::string Sob, Snr2, Param_s3, Param_s4;
void *_data;
;


So if anybody ever find this in his code, just throw it out and use proper classes or membervariables.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55224377%2fc-struct-throws-memory-dump%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    After to much trouble and helpfull links why not use struct with strings, i refactored it yesterday to a class, what runs like a charme:



     class DPic 
    public:
    DPic();
    ~DPic();

    double DM;
    double Angle;
    std::string Name;
    std::string Descr;
    double Param_d1, Param_d2, Param_d5;
    int Epuzae;
    int Param_i2;
    std::string Sob, Snr2, Param_s3, Param_s4;
    void *_data;
    ;


    So if anybody ever find this in his code, just throw it out and use proper classes or membervariables.






    share|improve this answer



























      0














      After to much trouble and helpfull links why not use struct with strings, i refactored it yesterday to a class, what runs like a charme:



       class DPic 
      public:
      DPic();
      ~DPic();

      double DM;
      double Angle;
      std::string Name;
      std::string Descr;
      double Param_d1, Param_d2, Param_d5;
      int Epuzae;
      int Param_i2;
      std::string Sob, Snr2, Param_s3, Param_s4;
      void *_data;
      ;


      So if anybody ever find this in his code, just throw it out and use proper classes or membervariables.






      share|improve this answer

























        0












        0








        0







        After to much trouble and helpfull links why not use struct with strings, i refactored it yesterday to a class, what runs like a charme:



         class DPic 
        public:
        DPic();
        ~DPic();

        double DM;
        double Angle;
        std::string Name;
        std::string Descr;
        double Param_d1, Param_d2, Param_d5;
        int Epuzae;
        int Param_i2;
        std::string Sob, Snr2, Param_s3, Param_s4;
        void *_data;
        ;


        So if anybody ever find this in his code, just throw it out and use proper classes or membervariables.






        share|improve this answer













        After to much trouble and helpfull links why not use struct with strings, i refactored it yesterday to a class, what runs like a charme:



         class DPic 
        public:
        DPic();
        ~DPic();

        double DM;
        double Angle;
        std::string Name;
        std::string Descr;
        double Param_d1, Param_d2, Param_d5;
        int Epuzae;
        int Param_i2;
        std::string Sob, Snr2, Param_s3, Param_s4;
        void *_data;
        ;


        So if anybody ever find this in his code, just throw it out and use proper classes or membervariables.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 10:45









        Lord_PinheadLord_Pinhead

        508 bronze badges




        508 bronze badges
















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55224377%2fc-struct-throws-memory-dump%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현