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

  • Home
  • SEARCH
  • 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 4024288
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:42:12+00:00 2026-05-20T10:42:12+00:00

So I have this struct composed of three NSPoint structures. typedef struct AOTriangle_ {

  • 0

So I have this struct composed of three NSPoint structures.

typedef struct AOTriangle_ {
    NSPoint a;
    NSPoint b;
    NSPoint c;
} AOTriangle;

I would like in some cases to reference the points as a,b,c and other cases as indices into an array.

Like so,

AOTriangle t;
t.a = NSMakePoint(0,0);
t.b = NSMakePoint(3,0);
t.c = NSMakePoint(0,4);

for(int i = 0; i < 3; ++i) {
    t[i].x += 5.0;
    t[i].y += 5.0;
}

This is the closest I’ve gotten, but you can see it isn’t exactly what I wanted.
Is there a way of doing this in Objective-C? Is the a better way than what I do below of accomplishing something similar – maybe with a union?

typedef struct AOTriangle_ {
    NSPoint a;
    NSPoint b;
    NSPoint c;
} AOTriangle;


AOTriangle t;
t.a = NSMakePoint(0,0);
t.b = NSMakePoint(3,0);
t.c = NSMakePoint(0,4);
NSPoint* t = (NSPoint*)&triangle;
for(int i = 0; i < 3; ++i) {
    t[i].x += 5.0;
    t[i].y += 5.0;
}
  • 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-05-20T10:42:13+00:00Added an answer on May 20, 2026 at 10:42 am

    Yes, you can use a “union“. I believe the declaration would go something like this:

    typedef struct AOTriangle_ {
        union {
            struct {
                NSPoint a;
                NSPoint b;
                NSPoint c;
            };
            NSPoint points[3];
        };
    } AOTriangle;
    

    A union is basically a way of saying “I can refer to the members of this struct as either a, b, or c, or as points[0], points[1], or points[2].”

    And you would use it like this:

    AOTriangle t;
    t.a = NSMakePoint(0,0);
    t.b = NSMakePoint(3,0);
    t.c = NSMakePoint(0,4);
    for(int i = 0; i < 3; ++i) {
        t.points[i].x += 5.0;
        t.points[i].y += 5.0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a struct like this: class Items { private: struct item { unsigned
I have code like this: template <typename T, typename U> struct MyStruct { T
In our code we used to have something like this: *(controller->bigstruct) = ( struct
I have this snippet of C code: #include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct Date {
I have this struct type definition: typedef struct { char *key; long canTag; long
I have this struct: #define sbuffer 128 #define xbuffer 1024 typedef struct{ char name[sbuffer];
I have structs like this: struct A { int a; virtual void do_stuff(A*a) {
In our project we have something like this: struct PointI { // methods for
I've a weird problem with malloc. I have this typedefs: typedef struct buffer {
I have this struct: struct Map { public int Size; public Map ( int

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.