Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] when i use array with with function the compiler assign as an error in the data type

Status
Not open for further replies.

mahm150

Full Member level 1
Joined
Dec 14, 2010
Messages
98
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Cairo, Egypt, Egypt
Activity points
2,001
my code
declare the function
****************
void arrange_message(unsigned char data_wrtn[16],unsigned char data_order);

call the function.
**************
arrange_message(THREE[j],1);

definition of function
*****************
oid arrange_message(unsigned char data_wrtn[16],unsigned char data_order)
{
unsigned char p;
if(data_order==1)
for(p=0;p<=7;p++)
{ temp1[p]= data_wrtn[p];}
}
****************************************
the error message of compiler is
parameter #1 of type unsigned char[] is compatible with type unsigned char[] specified in the
function arrange _message
 

oid arrange_message(unsigned char data_wrtn[16],unsigned char data_order)

typing error in above line, it should be

void arrange_message(unsigned char data_wrtn[16],unsigned char data_order)

---------- Post added at 16:10 ---------- Previous post was at 16:08 ----------

By the way this is not a complete code. there must be a main function.
 

You cannot manage some data wich was already pointed by function call.
Maybe, the correct declaration of 1rst argument should be without vector, despite you input a vector during function call :

Code:
void arrange_message(unsigned char [B]data_wrtn[/B] , unsigned char data_order);

+++
 

The array should be passed to the function using a pointer

**broken link removed**

Alex
 

According declaration code presented at post #3 and pointer indexing sugested by alexan_e, you could perform a single change at your program :

Code:
{ temp1[p]= *( &data_wrtn + p ) ;}

Note : I´m not sure anymore about pointer sintax, so some correction coud be done.

+++
 

when i use pointer as in the alexan_e it work but the dat in the array isnt correct
void arrange_message(unsigned char *,unsigned char data_order); with the code
****************************************

void arrange_message(unsigned char data_wrtn[],unsigned char data_order)
{
unsigned char p;
if(data_order==1)
{
for(p=0;p<=15;p++)
{
temp1[p]= data_wrtn[p];
}
}
}
 

It is missing the input argument variable declaration :

Code:
void arrange_message(unsigned char * (???) ,unsigned char data_order);

+++
 

Are calling the function like arrange_message(THREE,1);

Alex
 

What is wrong exactly,l the value of temp1?
post your code

Alex
 

Try this :


declare the function
****************
void arrange_message(unsigned char data_wrtn ,unsigned char data_order);

call the function.
**************
arrange_message(THREE[j],1);

definition of function
*****************
oid arrange_message(unsigned char data_wrtn , unsigned char data_order)
{
unsigned char p;
if(data_order==1)
for(p=0;p<=7;p++)
{ temp1[p]= *(&data_wrtn+p);}
}
****************************************

I did changes according what was sugested above.

+++
 

if you pass a char parameter than you can't use it as an address to get the rest of the array data, the memory position of this variable is not related to the array so you can't read the rest of the array like a contiguous memory space.

Alex
 

for alex this is my code
****************
arrange_message(THREE,1);
******************************

void arrange_message(unsigned char data_wrtn[],unsigned char data_order)
{
unsigned char p;
if(data_order==1)
{
for(p=0;p<=15;p++)
{
temp1[p]= data_wrtn[p];
}
}
}
*****************************************************************
THREE [16]={0x00,0x40,0x60,0x30,0x18,0x18,0x1C,0x0c,0x0c,0x0c,0x0c,0xFC,0xFc,0xAC,0x00,0x00};
*******************************************

---------- Post added at 18:41 ---------- Previous post was at 18:34 ----------

for andre_teprom
i try your code but it not work ok the data in is the address location of sram
 

and how do you check the value of temp1?
what was the value of temp1?

Alex
 
if you pass a char parameter than you can't use it as an address to get the rest of the array data, the memory position of this variable is not related to the array so you can't read the rest of the array like a contiguous memory space.

Alex
what do u mean ?

---------- Post added at 18:46 ---------- Previous post was at 18:44 ----------

and how do you check the value of temp1?
what was the value of temp1?

Alex
i see it avr simulator
 

He refered to the implementation I sugested.
Despite works many times, is not guaranteed everytime, due dynamic memory management is performed by compiler, and I was competiting with it.

+++
 

I have no idea why you see wrong data but I have seen AVR studio sometime show stupid values in variables or not update them.
Can you try with temp1[p]= THREE [p]; (make THREE a global variable first)
to see if you get correct result

Alex
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top