|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Unions |
Posted: Fri May 06, 2005 7:24 am |
|
|
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 |
Posted: Fri May 06, 2005 8:29 am |
|
|
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
|
|
Posted: Fri May 06, 2005 8:38 am |
|
|
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
|
|
Posted: Fri May 06, 2005 9:02 am |
|
|
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;
} |
|
|
|
|
|
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
|