From: Simon Wright <simon@pushface.org>
Subject: Re: function Is_Open (File : File_Type) return Boolean; :Text_io
Date: Mon, 26 Oct 2015 18:01:57 +0000
Date: 2015-10-26T18:01:57+00:00 [thread overview]
Message-ID: <lytwpdpkyy.fsf@pushface.org> (raw)
In-Reply-To: 75dd21a2-9265-44e4-a4d4-e2d96ffdecb1@googlegroups.com
comicfanzine@gmail.com writes:
> Thanks fot link .
>
> I want to create+open a file then use Is_Open , if the file have been create i want to put some text + the value of Is_Open(should be TRUE) .
>
> There is french in the code :
>
> [code]WITH Ada.Text_IO ; USE Ada.Text_IO ;
>
> PROCEDURE TestFichier IS
>
> MonFichier : File_type ;
>
> BEGIN
> Create( MonFichier,Name => "clone.adb");
> open(MonFichier,In_file,"clone.adb") ;
> if Is_Open(MonFichier) and MonFichier = true
> then put("Le fichier , ouvert ? : ",MonFichier);
> end if;
> END TestFichier ;[/code]
Compiling this with listing (gnatmake -gnatl testfichier.adb) gives
3. PROCEDURE TestFichier IS
4.
5. MonFichier : File_type ;
6.
7. BEGIN
8. Create( MonFichier,Name => "clone.adb");
9. open(MonFichier,In_file,"clone.adb") ;
10. if Is_Open(MonFichier) and MonFichier = true
|
>>> invalid operand types for operator "="
>>> left operand has private type "Ada.Text_Io.File_Type"
>>> right operand has type "Standard.Boolean"
11. then put("Le fichier , ouvert ? : ",MonFichier);
1 3
>>> no candidate interpretations match the actuals:
>>> too many arguments in call to "put"
>>> expected private type "Ada.Text_Io.File_Type"
>>> found a string type
>>> ==> in call to "Put" at a-textio.ads:241
>>> ==> in call to "Put" at a-textio.ads:207
12. end if;
13. END TestFichier ;
First, the compiler messages:
Line 10
-------
Is_Open returns Boolean, and MonFichier is a File_Type and can't be
compared to Boolean (in fact, it's limited private, so it can't by
default be compared to anything!) so I think you just meant
if Is_Open (MonFichier)
Line 11
-------
You have the arguments the wrong way round. You could use named
parameter association if you insist on this order,
Put (Item => "Le fichier , ouvert ? : ", File => MonFichier);
==============================
Second, the semantic problems: Create at line 8 will either result in an
opened writable file (MonFichier) or will raise an exception if the file
already existed.
If you get to line 9 (i.e. the Create was successful) you will get an
exception because the file is already open.
If you were to get to line 10, Is_Open would have to return True.
If you were to get to line 11 having executed line 9, you would get an
exception because you opened MonFichier read-only.
next prev parent reply other threads:[~2015-10-26 18:01 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-26 10:00 function Is_Open (File : File_Type) return Boolean; :Text_io comicfanzine
2015-10-26 11:27 ` Simon Wright
2015-10-26 13:25 ` comicfanzine
2015-10-26 18:01 ` Simon Wright [this message]
2015-10-26 19:03 ` AdaMagica
2015-10-27 11:30 ` Simon Wright
2015-10-26 18:02 ` Jeffrey R. Carter
2015-10-26 13:28 ` comicfanzine
2015-10-26 15:07 ` Jacob Sparre Andersen
2015-10-26 16:37 ` AdaMagica
2015-10-26 20:46 ` J-P. Rosen
2015-10-27 8:42 ` comicfanzine
2015-10-27 11:34 ` Simon Wright
2015-10-28 13:32 ` comicfanzine
2015-10-27 8:51 ` comicfanzine
2015-10-27 17:15 ` Jeffrey R. Carter
2015-10-26 22:48 ` Bob Duff
2015-10-27 8:30 ` Dmitry A. Kazakov
2015-10-27 13:30 ` Bob Duff
2015-10-27 14:00 ` G.B.
2015-10-27 15:26 ` Dmitry A. Kazakov
2015-10-27 16:43 ` G.B.
2015-10-27 20:04 ` Dmitry A. Kazakov
2015-10-28 11:06 ` Georg Bauhaus
2015-10-28 17:58 ` Randy Brukardt
2015-10-28 18:20 ` Dmitry A. Kazakov
2015-10-28 20:36 ` Bob Duff
2015-10-28 21:02 ` Dmitry A. Kazakov
2015-10-29 11:25 ` AdaMagica
2015-10-29 13:37 ` Dmitry A. Kazakov
2015-10-29 17:57 ` AdaMagica
2015-10-29 18:12 ` AdaMagica
2015-10-29 18:26 ` Dmitry A. Kazakov
2015-10-30 8:27 ` Jacob Sparre Andersen
2015-10-30 9:11 ` J-P. Rosen
2015-10-29 11:47 ` G.B.
2015-10-29 13:01 ` J-P. Rosen
2015-10-29 14:00 ` Dmitry A. Kazakov
2015-10-30 1:06 ` Georg Bauhaus
2015-10-30 8:39 ` Dmitry A. Kazakov
2015-10-30 14:32 ` G.B.
2015-10-30 16:20 ` Dmitry A. Kazakov
2015-10-30 19:07 ` G.B.
2015-10-31 9:31 ` Dmitry A. Kazakov
2015-10-31 11:17 ` Georg Bauhaus
2015-10-30 14:40 ` G.B.
2015-10-30 16:26 ` Dmitry A. Kazakov
2015-10-28 20:07 ` Bob Duff
2015-10-28 20:59 ` Dmitry A. Kazakov
2015-10-27 14:02 ` G.B.
2015-10-27 15:10 ` Dmitry A. Kazakov
2015-10-27 16:41 ` G.B.
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox