Jump to content
Sign in to follow this  
asmallri

You Can't Catch Me I'm Part Of A Union

Recommended Posts

Bug description:

If a union type is declared and an instance defined as separate steps the compilation fails with an error message. When the union type and variable are defined as a single step compilation succeeds.

 

This code does not work:

union SR_type{
       unsigned short result[2];
       unsigned long Seed;
       };

static SR_type ShiftRegister;

 

 

BoostC Optimizing C Compiler Version 1.4 Alpha (for PIC18 architecture)

http://www.picant.com/c2c/c.html

Copyright© 2004 Pavel Baranov

Copyright© 2004 David Hobday

 

 

MyRand.c(13): error: failure

failure

Exit code was 1.

Removing target: MyRand.obj

Failed to locate output file 'MyRand.obj'

Done

 

Failed

 

 

This does work:

static union SR_type{
       unsigned short result[2];
       unsigned long Seed;
       }ShiftRegister;

Share this post


Link to post
Share on other sites

union SR_type{
       unsigned short result[2];
       unsigned long Seed;
       };

SR_type ShiftRegister;

 

This is not an error. Your code doesn't compile because it's invalid. Using struc/union type without struct/union keyword in C is an error (though it is not in in C++). Either the 'union' keyword in the declaration or "typedefed" version of this union should be used:

 

union SR_type
{
       unsigned short result[2];
       unsigned long Seed;
};

typedef union SR_type CSR_type;

SR_type ShiftRegister; //error
union SR_type ShiftRegister; //ok
CSR_type ShiftRegister; //ok

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...