Menu
Search




Articles & Documents

Close Tutorials

Newsletter
To receive news about this website, consider subscribing to our Newsletter.
Subscribe
Unsubscribe
22 Subscribers
CPDB.Net

Friends News
Visits

   visitors

   visitors online

Webmaster - Infos
forum.gifForum - ppCompiler - Topic #54

Forum - Forum
ppCompiler - ppCompiler


active  Topic # 54  Assigning values to an array

09/11/2012 @ 18:00
by orlp

Anonymous



My original Palm code contains the statement

Var

...

tab:array[0..63] of char =
('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9','+','/');


Pepe does not seem to allow initialized variables - at least not for array variables. It asks for ';' after the word 'char'.

So I changed this to

Var 

tab:array[0..63] of char;

and in the main part added:

Begin

tab :=
('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9','+','/');

Pepe doesn't like this either - it asks for a ')' after character 'A'

Is there a way of initializing an array without using a loop.

Incidentally the array is actually a constant look-up table.What would be the best way of implementing it?

AfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBulgarianCatalanChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDetect languageDutchEnglishEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekHaitian CreoleHebrewHindiHungarianIcelandicIndonesianIrishItalianJapaneseKoreanLatinLatvianLithuanianMacedonianMalayMalteseNorwegianPersianPolishPortugueseRom anianRussianSerbianSlovakSlovenianSpanishSwahiliSwedishThaiTurkishUkrainianUrduVietnameseWelshYiddish⇄AfrikaansAlbanianArabicArmenianAzerbaijani BasqueBelarusianBulgarianCatalanChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutchEnglishEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekHaitian CreoleHebrewHindiHungarianIcelandicIndonesianIrishItalianJapaneseKoreanLatinLatvianLithuanianMacedonianMalayMalteseNorwegianPersianPolishPortugueseRom anianRussianSerbianSlovakSlovenianSpanishSwahiliSwedishThaiTurkishUkrainianUrduVietnameseWelshYiddishEnglish (auto-detected) » English


Oliver Pretzel

Write to orlp   Post an answer  Top

[]   

Answer n° 1
--------
10/11/2012 @ 12:26
by Philippe

Anonymous

visitor
The management of initialized data is different on Palm and Android, and this feature is not yet implemented on Pépé. I know how to do this, the problem is only my lack of free time.Waiting the implementation of the feature, I suggest two solutions.
1) Use the string[64] type, which is equivalent to the type "packed array[1..64] of char. For example:var tab:string[64]:
begin
  tab:='ABCDEDFH etc...
But this works only for arrays of char and requires to change your bounds in your program.

2) The second solution is a hack that take benefit of the inline assembler:
type
  ttab=array[0..63] of char;  ptab=^ttab;
function ctab:ptab;
asm
  mov r0,@data  mov pc,lr
@data
  dcb 'ABCDEFGHIJKLMNOPQRST'
end;

And then, when needing access to the constant tab, use for example
  c:=ctab^[i]:
Of course, it would be nicer if the compiler itself does the work. k


Rectifié par Philippe le 10/11/2012 @ 12:29


Rectifié par Philippe le 10/11/2012 @ 12:30
Write to Philippe   Post an answer  Top
Answer n° 2
--------
10/11/2012 @ 14:43
by orlp

Anonymous

visitor

Many thanks, Philippe, for your advice and also for developing Pépé (le Moko).

 I thought of using the string[64] type too, but wasn't sure that referencing individual characters by tab[x+1] would work. It will I suppose slightly slow down the program as it needs to reference the table quite frequently.

So I'll try this first. It seems simpler than using the asm + pointer workaround.

Oliver Pretzel

Rectified by orlp 10/11/2012 @ 14:44AfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBulgarianCatalanChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDetect languageDutchEnglishEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekHaitian CreoleHebrewHindiHungarianIcelandicIndonesianIrishItalianJapaneseKoreanLatinLatvianLithuanianMacedonianMalayMalteseNorwegianPersianPolishPortugueseRom anianRussianSerbianSlovakSlovenianSpanishSwahiliSwedishThaiTurkishUkrainianUrduVietnameseWelshYiddish⇄AfrikaansAlbanianArabicArmenianAzerbaijani BasqueBelarusianBulgarianCatalanChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutchEnglishEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekHaitian CreoleHebrewHindiHungarianIcelandicIndonesianIrishItalianJapaneseKoreanLatinLatvianLithuanianMacedonianMalayMalteseNorwegianPersianPolishPortugueseRom anianRussianSerbianSlovakSlovenianSpanishSwahiliSwedishThaiTurkishUkrainianUrduVietnameseWelshYiddishEnglish (auto-detected) » English

Rectified by orlp 10/11/2012 @ 14:45
Write to orlp   Post an answer  Top
Answer n° 3
--------
10/11/2012 @ 15:06
by Philippe

Anonymous

visitor
Oliver, the code generated for tab[x] (array 0..n-1) or tab[x+1] (string) is the same as the constant is automatically included on the base address of the variable.Tell me if it works as expected.Philippe.
Write to Philippe   Post an answer  Top
Answer n° 4
--------
10/11/2012 @ 17:11
by orlp

Anonymous

visitor

Philip,

I compiled using the string[64]. It compiled without a problem, but I had to change the code from Motorola big-endian to ARM little-endian to get the right results. Luckily my implementation uses a variant record type (and luckily Pepe understands variant records) - only the definition of this type needs to be changed. So its working now!

Thank you again,

Oliver



Oliver Pretzel


Rectified by orlp 10/11/2012 @ 17:15
  Post an answer  Top
Answer n° 5
--------
11/11/2012 @ 00:07
by Philippe

Anonymous

visitor
Thanks for info. Pépé (le Moko) remains (almost) a standard compliant Pascal compiler and thus recognize record with variants k
Philippe.
Write to Philippe   Post an answer  Top
active topic active   closed topic closed   Sticky Sticky   New New message   -   Correct Correct message   Close Close topic   Make sticky Make sticky
[]
Forum Topic  Forum 




^ Top ^