• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unions in Obj-C Code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unions in Obj-C Code


  • Subject: Re: Unions in Obj-C Code
  • From: Spencer Salazar <email@hidden>
  • Date: Wed, 4 Apr 2007 00:21:09 -0400

Hi Mike,
Yes, all valid C code is valid in Objective-C.  The problem here is that

serial_buff s;

is not valid C--that should be

union serial_buff s;

or at least, there should be a

typedef union serial_buff serial_buff;

somewhere in there.

hth,
spencer

On Apr 3, 2007, at 11:44 PM, Mike wrote:

Are unions supported in Obj-C? If so is there anything special I have to do to use them?

In my .h file I define a union like this:

typedef struct
{
   char        type;
   char        version;
   char        oem[ SER_OEM_SIZE ];
   char        alpha_chk[ 2 ];
   char        number[ SER_NUM_SIZE ];
   char        crc[ 2 ];
} serial_rec;

union serial_buff
{
   serial_rec    s;
   char        c[ sizeof( serial_rec ) ];
};

I then import that.h file into my .m file but any time I try to use the union I get an error on the declaration of my union serial_buff s:

- (BOOL)_validateSerialNumberAlpha:(char*)pserial_number
{
   BOOL            result = NO;
   serial_buff        s;

memset( &s, 0, sizeof( s ) );
memmove( s.c, pserial_number, ( strlen( pserial_number ) > sizeof( s.c )) ? sizeof( s.c ) : strlen( pserial_number ) );
.
.
.


Thanks,

Mike

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • SOLVED: Unions in Obj-C Code
      • From: Mike <email@hidden>
References: 
 >Unions in Obj-C Code (From: Mike <email@hidden>)

  • Prev by Date: Unions in Obj-C Code
  • Next by Date: Re: Unions in Obj-C Code
  • Previous by thread: Unions in Obj-C Code
  • Next by thread: SOLVED: Unions in Obj-C Code
  • Index(es):
    • Date
    • Thread