Anonymous struct problem with porting code to Linux

Source: Internet
Author: User

In the process of doing Windows Server migration to Linux, there was a problem with the compilation class

The following structure is defined in the code

struct msginfo{    Union     {      struct      {        OBJID idtype;        UINT  unexp;      };       struct       {        OBJID idtype;        UCHAR Ucresult;}      ;}    }

Under Windows Secure compilation passed, under the Linux GCC cannot be compiled.

This is because the anonymous struct is used in the code, the anonymous struct can be accessed directly under Windows, and the code is heavily used such as M_pinfo->idtype,

In the case of GCC, the lack of a name for the structure of the experience caused confusion.

On this issue, you can look at this discussion string

Http://stackoverflow.com/questions/1972003/how-to-compile-c-code-with-anonymous-structs-unions

You can see that if you add some compile parameters, you can ensure that the compilation is passed,

And the new C11 and c++11 are allowed to do this.

And I'm here for the transplant, for the time being the old scheme, because the GCC version is low, give each struct a name

struct msginfo{    Union     {      struct      {        OBJID idtype;        UINT  unexp;      } Expinfo;       struct       {        OBJID idtype;        UCHAR ucresult;      } Learninfo;}    }

That's all.

You can then use M_pinfo->learninfo.idtype to access the

Anonymous struct problem with porting code to Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.