Menu

two or more data types in declaration of ...

2007-11-05
2012-09-26
  • goodTweetyBird

    goodTweetyBird - 2007-11-05

    Greetings,

    I get the message
    "two or more data types in definition of myStruct" with the following example.

    main()
    {
    struct typeMyStruct = {
    float a;
    float b;
    };

    struct typeMyStruct myStruct = {
    {1.0, 2.0},
    {3.0, 4.0}
    }

    }

     
    • goodTweetyBird

      goodTweetyBird - 2007-11-05

      Hmmm,

      Don't guess I will be getting any points for attention to detail tonight.

      Yes the cut and paste worked fine. I had left the semi-colon off the end of the definition. The compiler is on an offline computer and I hurriedly copied from memory. I put your snippet on a thumb drive and took it to the other machine to check it out. I did not do that when posting the example problem; another mistake. Also I should have known to look at the line before where the compiler said it was.

      It will come back to me a day or two. It is amazing how fast I become rusty.

      Thanks again,

      gtb

       
    • Osito

      Osito - 2007-11-05

      I'm not sure, but I think this is what you want:

      struct typeMyStruct {
      float a;
      float b;
      };

      struct typeMyStruct myStruct[] = {
      {1.0, 2.0},
      {3.0, 4.0}
      };

      The first struct line defines the type, and the second struct line defines an array of two of those structs.

       
    • goodTweetyBird

      goodTweetyBird - 2007-11-05

      Doh! How stupid of me.

      Thanks.

       
    • goodTweetyBird

      goodTweetyBird - 2007-11-05

      Sorry for the sloppy post. Now I have removed the offending = from my example and this is the code that causes the error.

      main()
      {
      struct typeMyStruct {
      float a;
      float b;
      };

      struct typeMyStruct myStruct = {
      {1.0, 2.0},
      {3.0, 4.0}
      }

      }

       
      • Osito

        Osito - 2007-11-05

        Actually my post solved three problems: the extra = sign in the definition of the struct, the missing array brackets [] in myStruct, and the missing semicolon at the very end. I'm assuming that since you have two groups of two floats in your myStruct, you want it to be an array and not a single instance.

        Try pasting my code into your program and see if it compiles.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.