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

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript