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
 

qwertyuiop415263

Full Member level 4
Joined
Mar 26, 2010
Messages
231
Helped
50
Reputation
102
Reaction score
39
Trophy points
1,308
Location
Pakistan
Activity points
2,414
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.
 

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,479
Helped
1,183
Reputation
2,385
Reaction score
1,181
Trophy points
1,403
Location
Brazil
Activity points
54,962
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);

+++
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,888
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,371
The array should be passed to the function using a pointer

**broken link removed**

Alex
 

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,479
Helped
1,183
Reputation
2,385
Reaction score
1,181
Trophy points
1,403
Location
Brazil
Activity points
54,962
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.

+++
 

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
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];
}
}
}
 

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,479
Helped
1,183
Reputation
2,385
Reaction score
1,181
Trophy points
1,403
Location
Brazil
Activity points
54,962
It is missing the input argument variable declaration :

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

+++
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,888
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,371
Are calling the function like arrange_message(THREE,1);

Alex
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,888
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,371
What is wrong exactly,l the value of temp1?
post your code

Alex
 

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,479
Helped
1,183
Reputation
2,385
Reaction score
1,181
Trophy points
1,403
Location
Brazil
Activity points
54,962
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.

+++
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,888
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,371
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
 

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
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
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,888
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,371
and how do you check the value of temp1?
what was the value of temp1?

Alex
 

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
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
 

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,479
Helped
1,183
Reputation
2,385
Reaction score
1,181
Trophy points
1,403
Location
Brazil
Activity points
54,962
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.

+++
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,888
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,371
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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top