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

Array concatenation

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



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

Array concatenation
PostPosted: Wed Oct 06, 2004 4:14 am     Reply with quote

Is there any way to concatenate for example 2 bytes array to 1 variable?
Say:
BYTE array[2];
int Var; //2 bytes

I want to write the whatever in the array into the Var.

Thank you
_________________
Alex
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Oct 06, 2004 5:12 am     Reply with quote

Use a union

Code:

union my_union {
     int 16   var;
     int8 array[2];
     } my_union_variable;
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Wed Oct 06, 2004 5:17 am     Reply with quote

int16 and int8
are not recognized for some reason
and also cannot make a variable more than 8 bits.
it does recognize 'long', but the variable is still 8 bits
_________________
Alex
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Oct 06, 2004 5:29 am     Reply with quote

alexz wrote:
int16 and int8
are not recognized for some reason
and also cannot make a variable more than 8 bits.
it does recognize 'long', but the variable is still 8 bits


ok - so int8 and int16 are not defined.
how do you know the long variable is only 8 bits? Are you sure you aren't running into a typecast problem?
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Wed Oct 06, 2004 5:32 am     Reply with quote

I am not sure.
I just cant find a way to define a 16bit variable :(
I already tryed #type int16=16
_________________
Alex
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Oct 06, 2004 5:52 am     Reply with quote

Quote:
I just cant find a way to define a 16bit variable :(


A long is a 16 bit variable
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Wed Oct 06, 2004 5:54 am     Reply with quote

I know that.
But in the watch window it is still 8
_________________
Alex
Mark



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

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

PostPosted: Wed Oct 06, 2004 7:59 am     Reply with quote

Your version must be old as dirt!

Code:

typedef uint8_t int;
typedef int18_t signed int;
typedef uint16_t long;
typedef int16_t signed long;
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 06, 2004 8:53 am     Reply with quote

What version of the compiler did you say you were using?

We are trying to help,.. but the assignment is easy. and we don't understand the problem?

int8 array[2];
int16 Var;

Var=make16(array[0],array[1]); //whatever order you want


I think the problem is the compiler version or the watch window.

(ps i think its the watch window)


Last edited by treitmey on Wed Oct 06, 2004 9:01 am; edited 3 times in total
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Wed Oct 06, 2004 8:55 am     Reply with quote

version CCS 3.207
_________________
Alex
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 06, 2004 9:24 am     Reply with quote

Here is a little test progrm. in watch window put in addr,h tmp,h

the ",h" displays it in hex digits,.. 4 bits per 1 hex digit
btw. I used 3.212 compiler

Code:
#include <16F877.h>
#device *=16
#CASE
#use delay(clock=16000000)
#fuses HS,NOWDT,NOPROTECT,NOLVP
#define VER_MAJOR 1
#define VER_MINOR 00
#define INTS_PER_MIN_TMR2 3660
#zero_ram
#use rs232(baud=57600,xmit=PIN_A2,INVERT,stream=DEBUG) // STDERR(same as DEBUG)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,stream=FA403)  //This is talking to FA403 wireless
void main(void)
{
  int8 tmp[2];
  int16 addr;
  tmp[0]=1;
  tmp[1]=2;

   addr=make16(tmp[0],tmp[1]);
  while(1)
  {
  }
}

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