Menu
Recherche




Articles & Documents

Fermer Tutoriaux

Lettre d'information
Pour avoir des nouvelles de ce site, inscrivez-vous à notre Newsletter.
S'abonner
Se désabonner
22 Abonnés
CPDB.Net

Nouvelles des Amis
Visites

   visiteurs

   visiteurs en ligne

Webmaster - Infos
forum.gifForum - ppCompiler - Sujet n°54

Forum - Forum
ppCompiler - ppCompiler


actif  Sujet n° 54  Assigning values to an array

le 09/11/2012 @ 18:00
par orlp

Anonyme



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

Ecrire à orlp   Poster une réponse  Haut

[]   

Réponse n° 1
--------
le 10/11/2012 @ 12:26
par Philippe

Anonyme

visiteur
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
Ecrire à Philippe   Poster une réponse  Haut
Réponse n° 2
--------
le 10/11/2012 @ 14:43
par orlp

Anonyme

visiteur

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
Ecrire à orlp   Poster une réponse  Haut
Réponse n° 3
--------
le 10/11/2012 @ 15:06
par Philippe

Anonyme

visiteur
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.
Ecrire à Philippe   Poster une réponse  Haut
Réponse n° 4
--------
le 10/11/2012 @ 17:11
par orlp

Anonyme

visiteur

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
  Poster une réponse  Haut
Réponse n° 5
--------
le 11/11/2012 @ 00:07
par Philippe

Anonyme

visiteur
Thanks for info. Pépé (le Moko) remains (almost) a standard compliant Pascal compiler and thus recognize record with variants k
Philippe.
Ecrire à Philippe   Poster une réponse  Haut
actif sujet actif   clos sujet clos   Important! Important!   Nouveau Nouveau message   -   Rectifier Rectifier message   Clôturer Clôturer sujet   Remonter Remonter
[]
Catégories de discussion  Forum 




^ Haut ^