Thread: How to define semantics of object access when no member is specified?

  1. #1
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587

    How to define semantics of object access when no member is specified?

    Is there a way to define how to access an object(struct/union) when no member is specified? For example, could I define a struct ...
    Code:
    struct{
         int a;
         int b;
    }c;
    ... and define that c should be accessed as an int when no member is specified, effectively making the a 3 int struct? The difference between this and anonymous objects is that I want a and b to still be accessed as members, like c.a and c.b.

    No, I CAN'T use C++.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    No.

    The struct is a defined object with specified contents and a known size.

    If you try to access it as anything but a struct, you will either a) garbage the contents, b) cause a run time error or c) get told your code can't be compiled...

    If you need a third int, add it to the struct or define another variable.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RS232 connection set up
    By cs342 in forum C Programming
    Replies: 25
    Last Post: 05-26-2010, 03:57 AM
  2. USB1: Undefined reference to...
    By Oaktree in forum C Programming
    Replies: 6
    Last Post: 01-21-2010, 11:33 AM
  3. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  4. Replies: 2
    Last Post: 04-19-2008, 12:06 AM
  5. queued signals problem, C programming related
    By Unregistered in forum Linux Programming
    Replies: 3
    Last Post: 01-22-2002, 12:30 AM