Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8960527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:40:42+00:00 2026-06-15T15:40:42+00:00

This is probably something really stupid that I’m doing wrong, but I can’t figure

  • 0

This is probably something really stupid that I’m doing wrong, but I can’t figure out what it is.

I have a struct PDRect, the members of which are a PDPoint and PDSize:

typedef struct {
    GLfloat x, y;
} PDPoint;

typedef struct {
    GLfloat width, height;
} PDSize;

typedef struct {
    PDPoint origin;
    PDSize size;
} PDRect;

When I instantiate one, like so:

PDRect rect = {
    .origin = {
        .x = 0,
        .y = 0
    },
    .size = {
        .height = .5,
        .width = .5
    }
};

the debugger says that rect.origin.width and rect.origin.height both exist and equal 0, and rect.size.x and rect.size.y both exist and equal .5. I don’t know why this is happening.

EDIT FOR CLARITY: My confusion is why rect.origin (which is a PDPoint) has height and width values associated with it and rect.size (which is a PDSize) has x and y values associated with it. Shouldn’t the origin just have x and y and size just have height and width?

EDIT: It actually fixed it to have them declared non-anonymously, i.e.:

typedef struct _PDPoint {
    GLfloat x, y;
} PDPoint;

typedef struct _PDSize {
    GLfloat width, height;
} PDSize;

typedef struct _PDRect {
    PDPoint origin;
    PDSize size;
} PDRect;

I’m still not sure I actually understand why that would make a difference, but it seems to have resolved the issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:40:43+00:00Added an answer on June 15, 2026 at 3:40 pm

    I think the problem happened cause you were using anonymous structs and typedefing at the same time. When a C compiler sees the

    struct {...} name;
    

    construct it actually changes is it to

    struct anonymous {...} name;
    

    Now here is what i think is happening:… and i say i think cause i can’t reproduce your example. i just changed the types to floats and run it on FreeBSD amd64/gcc version 4.2.1 20070831. code below.

    #include <stdio.h>
    
    typedef struct {
      float x, y;
    } PDPoint;
    
    typedef struct {
      float width, height;
    } PDSize;
    
    typedef struct {
      PDPoint origin;
      PDSize size;
    } PDRect;
    
    int main(int argc, char *argv[]) {
      PDRect rect = {
        .origin = {
          .x = 1,
          .y = 1
        },
        .size = {
          .height = .5,
          .width = .5
        }
      };
      printf("w:%f h:%f x:%f y:%f\n",rect.size.width,rect.size.height,
          rect.origin.x,rect.origin.y);
      return 0;
    }
    

    outputs

    w:0.500000 h:0.500000 x:1.000000 y:1.000000

    as it should…
    If you could try the following it would be interesting. change one of the structs to hold
    integers and see if the swapping is happening again. Also try to initialize the 2 fields to something non-zero to check if you are causing it or its the default assigned value.
    What i think is going on is that with your code the compiler does things in that order:

    a)It sees a struct called anonymous that takes 2 floats , stores it in a stack and names it PDPoint

    b)It sees a struct called anonymous that takes 2 floats , stores it in the stack and names it PDSize

    c)While looking up PDPoint to define the third struct it pop()s from the stack the struct called anonymous that takes 2 floats. but at this point this resolves to PDSize.

    d)for PDSize ony PDPoint is left on the stack and indeed its a struct called anonymous that takes 2 floats. 😉

    The proper way to typedef and declare structs is

    typedef struct name_t { ... } name;
    

    although some will argue that nowdays you can ditch the _t convention (and it is reserved for POSIX).
    tl;dr: be careful with anonymous structs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably something stupid, but I really can't figure it out myself. I'm
I'm probably doing something realy stupid but I cant get this to work: var
This is probably something really simple but for some reason I just can't seem
This is probably something stupid I am missing but it has really got me
This probably something really simple, but I have never used CAShapeLayers before, I imported
This is probably something fundamental and stupid that I've missed, but the various workarounds
I'm probably doing something wrong here because this looks a bit stupid. I'm setting
This may sound really noobish, and I'm probably missing something really stupid.. But, I'm
This probably sounds really stupid, but I just can't get a binding to an
This is probably something really simple but I cant see what! Any images I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.