CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Unions

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Unions
PostPosted: Fri May 06, 2005 7:24 am     Reply with quote

It may seem trivial but I have searched the forum about unions and still have not solved my problem. With compiler version 3.224 I cannot compile any unions or maybe I am just coding them wrong. Here is test sample that I am missing somthing on. Any help would be appreciated.
Code:

#include <16f877a.h>
#DEVICE ADC=8
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000)

typedef union {

   int i[4];
   char letter[4];
   long test;
} maybe;

maybe.i[2] = 4;

maybe.letter = "a";

maybe.test = 5500;

main () {

}

Thanks,
Guest








Re: Unions
PostPosted: Fri May 06, 2005 8:29 am     Reply with quote

Anonymous wrote:
It may seem trivial but I have searched the forum about unions and still have not solved my problem. With compiler version 3.224 I cannot compile any unions or maybe I am just coding them wrong. Here is test sample that I am missing somthing on. Any help would be appreciated.
Code:

#include <16f877a.h>
#DEVICE ADC=8
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000)

typedef union {

   int i[4];
   char letter[4];
   long test;
} maybe;

maybe.i[2] = 4;

maybe.letter = "a";

maybe.test = 5500;

main () {

}

Thanks,



try

union tagname
{
....
} maybe;




Scott
Guest








PostPosted: Fri May 06, 2005 8:38 am     Reply with quote

Well I tried it and no success. Did you actually compile that Code? The actual code I am trying to use is:
Code:

#include <16f877a.h>
#DEVICE ADC=8
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000)

typedef union {

   int i[4];
   char letter[4];
   long test;
} maybe;

maybe question;

question.i[2] = 4;
question.letter[1] = "a";
question.test = 5500;

main () {
}

Sam
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri May 06, 2005 9:02 am     Reply with quote

First, for a char use 'a' instead of "a".
Second, you have to make you assignments in a function not in the declaration!

Code:

#include <16f877a.h>
#DEVICE ADC=8
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000)

typedef union {

   int i[4];
   char letter[4];
   long test;
} maybe;

maybe question;


main () {
  question.i[2] = 4;
  question.letter[1] = 'a';
  question.test = 5500;

}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group