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 7601191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:06:33+00:00 2026-05-30T23:06:33+00:00

Is it possible to rename the variables of a struct when using typedef? typedef

  • 0

Is it possible to rename the variables of a struct when using typedef?

typedef struct {
    float x;
    float y;
    float z;
} Vector;

typedef Vector {
    float r;
    float g;
    float b;
} Color;
  • 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-30T23:06:34+00:00Added an answer on May 30, 2026 at 11:06 pm

    Presumably you mean some sort of typedef that would let you say: “a Color is the same as a Vector, but with the names x, y and z changed to r, g and b, respectively”?

    If so, the answer is no, C doesn’t provide that (nor can I think of anything it provides that would be a reasonably close substitute).

    Edit: you can, however, have a function operate on either one pretty easily:

    typedef union { 
        Color c;
        Vector v;
    } cv;
    
    int my_func(cv *value);
    

    C guarantees that the initial sequence of items with the same types in the same order (which, in this case is all of them) can be worked with via either selector equally. In other words, if you put a Vector into your cv and pass it to a function, the function can work with those three items as either r, g and b or as x, y and z without any problem (e.g., if it writes to g, that will change y, if you view it as a Vector instead of a Color).

    Edit: C99, §6.5.2.3/5:

    One special guarantee is made in order to simplify the use of unions: if a union contains several structures that share a common initial sequence (see below), and if the union object currently contains one of these structures, it is permitted to inspect the common initial part of any of them anywhere that a declaration of the complete type of the union is visible. Two structures share a common initial sequence if corresponding members have compatible types (and, for bit-fields, the same widths) for a sequence of one or more initial members.

    In this case, all the members of c and v have the same types in the same order, so this rule applies to the entirety of either member. Rereading things, however, this only allows you to “inspect” the common initial sequence, which probably doesn’t include writing to it (though I find it hard to imagine how you’d make reading from any member work without making writing work as well).

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

Sidebar

Related Questions

Is it possible to rename a list in Sharepoint 2007 using the web interface?
Is it possible to rename a report section in a crystal reports using the
Is this possible to rename a folder on a FTP Server using the FTP
Is it possible to rename a cell, like A1 to firstCell in C#.?am using
Is it possible to change filenames in svn using wildcards? for example: svn rename
Is it possible to rename all the tabs in a jQuery UI tab control?
Is it possible to rename a MySQL table? If so, how?
Is it possible to rename a namespace name in an existing API without breaking
Is it possible to rename file when trying to download it? For example, I
Is it possible to rename/refactor a class file and have it rename the actual

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.