constant array

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
tass
Posts: 19
Joined: Sat Jan 19, 2008 8:37 am
Location: France

constant array

Post by tass » Tue Apr 01, 2008 8:31 am

hellow all
i have a problem to get the address of a constant array in the program memory in order to pass it as a parameter to a function the constant is declared in a separate module :

Code: Select all

module Mymodule
public const MyArray() as byte = (.............)
and the code of the programm is like this

Code: Select all

dim addr as longword
...
...
add = addresssof(MyArray(0))
mysub(addr)
the compiler error is : the expression can not be passed by refernce
is there another solution?

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Tue Apr 01, 2008 9:19 am

use this:

Code: Select all


addr = @MyArray

note that you can pass your CONST ARRAY directly as a param to your sub by specifiying ByRefConst as param passing type.


regards
octal

tass
Posts: 19
Joined: Sat Jan 19, 2008 8:37 am
Location: France

Post by tass » Tue Apr 01, 2008 11:57 am

I testet it but i have the same merror message
and i cant pass my const as a param because i must access the data by calculating its position in the array witch is too long (30 Kbytes)

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Tue Apr 01, 2008 12:33 pm

copy and paste this code

Code: Select all

Public Const MyArray() As Byte = (1,2,3,4,5)
Dim addr As Word
addr = @MyArray
End
then compile. Do you still see an error message?

> and i cant pass my const as a param because i must
> access the data by calculating its position in the array
> witch is too long (30 Kbytes)

Arrays are passed by reference, not value.

tass
Posts: 19
Joined: Sat Jan 19, 2008 8:37 am
Location: France

Post by tass » Tue Apr 01, 2008 4:50 pm

thanks DAVID it's OK realy there isn't a problem because a have done a mistake because i wrote in the code @MyArray() so using @MyArray whithout brackets was the solution
I have used this big const array to test the porting of MPFS2.c to swordfih basic and it's works fine now , i hope that i will finish the porting of the rest of the microchip TCT/IP stack in 2-3 weeks when i purchase a licene (now i'm using SE version)

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Tue Apr 01, 2008 7:34 pm

Good luck with that - let us know how you get on...

Post Reply