Lecture de Interface.C.Char_Array 
Author Message
 Lecture de Interface.C.Char_Array

Bonjour,

Quelque chose m'echappe : voila quelques heures que j'essaye de
lire un tableau de type Char_Array dans un flux, or autant
je n'ai aucun probleme a l'ecriture (le fichier ecrit sur disque
est correct), autant la lecture se passe de facon mysterieuse
(la chaine lue est vide !).

Mon programme de test est le suivant, j'espere que mon erreur
vous sautera aux yeux !

with Ada.Streams.Stream_Io; use Ada.Streams.Stream_Io;
with Interfaces.C;
with Ada.Text_Io;

procedure Foo is
   package C renames Interfaces.C;
   package Tio renames Ada.Text_Io;

   subtype Words is C.Char_Array (0 .. 25);

   procedure Write (W : in Words) is
      F : File_Type;
      S : Stream_Access;
   begin
      Create (F, Mode => Out_File, Name => "test");
      S := Stream (F);
      Words'Write (S, W);
      Close (F);
   end Write;

   procedure Read (W : out Words) is
      F : File_Type;
      S : Stream_Access;
   begin
      Open (F, Mode => In_File, Name => "test");
      S := Stream (F);
      Words'Read (S, W);
      Close (F);
   end Read;

   Dummy_Count : C.Size_T;
   Test : Words;
begin
   C.To_C ("test phrase", Test, Dummy_Count);

   Tio.Put_Line (C.To_Ada (Test)); -- Affiche bien "test phrase"
   Write (Test);                   -- Le fichier sauvegarde est correct
   Read (Test);                    -- Semble lire une chaine vide (?)
   Tio.Put_Line (C.To_Ada (Test)); -- Affiche une chaine vide
end Foo;

--
Alexandre Duret-Lutz



Sat, 07 Dec 2002 03:00:00 GMT  
 Lecture de Interface.C.Char_Array

Tu devrais poser cette question dans fr.comp.lang.ada :)

Pascal.

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



Sat, 07 Dec 2002 03:00:00 GMT  
 Lecture de Interface.C.Char_Array
(Translation in english: the program doesn't re-read
the C string just saved.)
Seems a bug in GNAT (tested with 3.10p & 3.12p for DOS)!
Under Aonix ObjectAda it works fine...
______________________________________________________
Gautier  --  http://members.xoom.com/gdemont/gsoft.htm


Sat, 07 Dec 2002 03:00:00 GMT  
 Lecture de Interface.C.Char_Array

 adl> Bonjour,

[...]

Appologies to all, I posted this to the wrong newsgroup: I missed
the `fr.' in `fr.comp.lang.ada' ...  

Translation:

I'm trying to read a Char_Array from a Stream.  As shows the
included program, that's doesn't work (unless I made a big
mistake which I hope will be obvious to you all): I can write a
Char_Array to disk, but can't read it back.

If this is a Gnat bug, do you see a way to work around it?

with Ada.Streams.Stream_Io; use Ada.Streams.Stream_Io;
with Interfaces.C;
with Ada.Text_Io;

procedure Foo is
   package C renames Interfaces.C;
   package Tio renames Ada.Text_Io;

   subtype Words is C.Char_Array (0 .. 25);

   procedure Write(W : in Words) is
      F : File_Type;
      S : Stream_Access;
   begin
      Create (F, Mode => Out_File, Name => "test");
      S := Stream (F);
      Words'Write (S, W);
      Close (F);
   end;

   procedure Read(W : out Words) is
      F : File_Type;
      S : Stream_Access;
   begin
      Open (F, Mode => In_File, Name => "test");
      S := Stream (F);
      Words'Read (S, W);
      Close (F);
   end;

   Dummy_Count : C.Size_T;
   Test : Words;
begin
   C.To_C ("test phrase", Test, Dummy_Count);
   Tio.Put_Line (C.To_Ada (Test)); -- print "test phrase"
   Write (Test);
        -- The file is correct
   Read (Test);
   Tio.Put_Line (C.To_Ada (Test)); -- print an empty line
end Foo;

--
Alexandre Duret-Lutz



Sun, 08 Dec 2002 03:00:00 GMT  
 Lecture de Interface.C.Char_Array
Dans comp.lang.ada, Alexandre Duret-Lutz  crit :

Quote:
>If this is a Gnat bug, do you see a way to work around it?

This looks like a GNAT 3.12p bug. Your program works correctly
with GNAT 3.13a1.

Thomas.

--



Mon, 09 Dec 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Lecture dynamique de membre(s) de PDS

2. GNAT mirror at ftp.cs.tu-berlin.de (Germany)

3. Data Interface with CS/3

4. to CS: or not to CS: in F-PC assembler

5. CONEXION DE CLARION CON ARCHIVO DE COBOL

6. SPANISH - El ABC de Clarion - Tarjetas de crédito

7. SPANISH - Participa GRATIS en sorteo de El ABC de Clarion

8. SPANISH - El ABC de Clarion - Artículos y Tips de la Semana

9. Necesito ayuda de como pasar datos de Excel a un programa Clipper

10. clipper 5.2 y PISTOLA LECTORA DE CODIGOS DE BARRAS

11. problemas con los generadores de formas de onda.

12. Preciso programador de bases de dados (Visual)

 

 
Powered by phpBB® Forum Software