* Re: Character'First, ASCII.NUL and others (Was: Re: TCP/IP Sockets with GNAT.Sockets)
@ 2005-05-15 2:42 Frank Beard
0 siblings, 0 replies; 4+ messages in thread
From: Frank Beard @ 2005-05-15 2:42 UTC (permalink / raw)
To: Manuel G. R., comp.lang.ada
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 1720 bytes --]
Well, I was actually talking about what is really
referred to as the Extended ASCII set:
http://www.computerhope.com/jargon/a/ascii.htm
or
http://www.lookuptables.com/
Maybe I've just been working in the Windows world too
long:
http://telecom.tbi.net/asc-ibm.html
Frank
--- "Manuel G. R." <mgrojo@ya.com> wrote:
> Frank Beard wrote:
> > The ASCII package became one of the "Obsolescent
> Features" before the
> > ASCII standard was expanded from 128 to 256
> characters. Even if it
> > didn't expand, it would probably never be gone
> from the Ada standard,
> > for backward compatibility reasons. The only risk
> would be trying to go
> > beyond character'pos = 127.
> >
> > Now that the ASCII standard is expanded, there's
> probably no reason not
> > to use it. But, if you're worried about it you
> can just do the rename
> > as*/ /*Adrien pointed out in his reply.
> >
>
> ASCII is a 7 bit character set and never was
> expanded to 256 characters.
> You are probably refering to one of its supersets,
> e.g. Latin 1 (ISO 8859-1)
>
> http://en.wikipedia.org/wiki/ASCII
> http://en.wikipedia.org/wiki/ISO_8859
>
> But I think you are right, ASCII package should
> never leave the standard.
>
> --
> Ada programming tutorial:
> http://en.wikibooks.org/wiki/Programming:Ada
> Tutorial de programaci�n en Ada:
>
http://es.wikibooks.org/wiki/Programaci%C3%B3n_en_Ada
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
>
http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <mailman.112.1115585537.24457.comp.lang.ada@ada-france.org>]
* TCP/IP Sockets with GNAT.Sockets
@ 2005-05-02 2:42 fabio de francesco
2005-05-02 12:11 ` Adrien Plisson
0 siblings, 1 reply; 4+ messages in thread
From: fabio de francesco @ 2005-05-02 2:42 UTC (permalink / raw)
Hello,
Today is the first time I try to use sockets in Ada programs, even if I
have some practical knowledge of programming with TCP/IP sockets in C.
Because I didn't find any better tutorial on working with GNAT.Sockets
I am relying on comments in file g-socket.ads from GCC/GNAT sources
where there is not a complete and detailed coverage of the subject.
(1) Do you know any better tutorial?
Then I wrote two little programs in order to try the package. A server
waits for connections and a client sends a string and receive an echo
from the first one. The client can also shutdown the server by sending
a predefined string.
I hadn't too many problems with exchanging messages and everything
works. The problem is that I was only able to use Streams for
communicating between them and I can't understand at all how to use
Receive_Socket() and Send_Socket() because they use
"Stream_Element_Array" and "Stream_Element _Offset" in place of
Strings. I know that by using Streams they can't communicate with C
programs and I've read that Streams are everything but efficient.
(2) The following is an extract from the client program. It compiles
and works as it is. May you please explain how to modify it in order to
use the above-mentioned functions in place of Input() and Output()? If
the problem can be solved by copying Strings to Stream_Element_Array
and back, how can I do that?
-- file client.adb
with GNAT.Sockets, Ada.Text_IO,
Ada.Strings.Unbounded, Ada.Command_Line;
use GNAT.Sockets, Ada.Text_IO,
Ada.Strings.Unbounded, Ada.Command_Line;
procedure Client is
Socket : Socket_Type;
Address : Sock_Addr_Type;
Channel : Stream_Access;
Reply : Unbounded_String;
begin
Initialize;
Create_Socket( Socket );
Address.Addr := Inet_Addr( "127.0.0.1" );
Address.Port := 9876;
Connect_Socket( Socket, Address );
Channel := Stream( Socket );
if Argument_Count > 0 then
if Argument(1) = "kill" then
Put_Line( "asking server to shutdown" );
String'Output( Channel, "kill" );
else
Put_Line( "sending """ & Argument( 1 ) & """" );
String'Output( Channel, Argument( 1 ) );
end if;
Reply := Unbounded_String'Input( Channel );
Put_Line( "server echos """ & To_String( Reply ) & """" );
end if;
Free( Channel );
Close_Socket( Socket );
Finalize;
end Client;
-- end of client.adb
Thanks to all of you who will reply.
fabio de francesco
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: TCP/IP Sockets with GNAT.Sockets
2005-05-02 2:42 TCP/IP Sockets with GNAT.Sockets fabio de francesco
@ 2005-05-02 12:11 ` Adrien Plisson
2005-05-02 14:55 ` fabio de francesco
0 siblings, 1 reply; 4+ messages in thread
From: Adrien Plisson @ 2005-05-02 12:11 UTC (permalink / raw)
fabio de francesco wrote:
> Hello,
hello !
> Today is the first time I try to use sockets in Ada programs, even if I
> have some practical knowledge of programming with TCP/IP sockets in C.
> Because I didn't find any better tutorial on working with GNAT.Sockets
> I am relying on comments in file g-socket.ads from GCC/GNAT sources
> where there is not a complete and detailed coverage of the subject.
>
> (1) Do you know any better tutorial?
personnally, no. the GNAT reference manual says:
"The chapter here simply gives a brief summary of the facilities
available. The full documentation is found in the spec file for the
package. The full sources of these library packages, including both
spec and body, are provided with all GNAT releases."
so, you can rely on the comments in g-socket.ads (which contains some
full examples). also, the behavior is identical to other sockets
implementation (C, Python, or others) so don't hesitate to read
manuals for other languages.
the only big difference is in Streams, which is Ada specific...
[...]
> I hadn't too many problems with exchanging messages and everything
> works. The problem is that I was only able to use Streams for
> communicating between them and I can't understand at all how to use
> Receive_Socket() and Send_Socket() because they use
> "Stream_Element_Array" and "Stream_Element _Offset" in place of
> Strings. I know that by using Streams they can't communicate with C
> programs and I've read that Streams are everything but efficient.
streams are not specially inefficient (to the contrary, my dear). the
problem is that many people do not clearly understand them !
so let's explain Ada streams:
streams are defined as a tagged record in Ada.Streams, which is to be
derived in order to implement stream specific behavior: how to send or
receive data from stream. Streams define 2 procedures for reading and
writing data onto them. on this side of streams, data are represented
as Stream_Element grouped in Stream_Element_Array. a single
Stream_Element may represent a byte you send over the network for
example.
at this end of streams, there is no data type: what is important is
the type of streams you manipulate.
on the other end, you are concerned with data types you read from or
write to stream, but not with the type of streams. on this end, every
streams are equal, may it be file, socket, or anything else. this is
achieved through stream oriented attributes: 'Read, 'Write, 'Input and
'Output. those attributes allow you to read or write a specific data
type from/to a stream. for example: Integer'Input( S ) will read an
integer from the stream S (whatever stream type S is). the behavior of
those attribute may be overriden through an attribute definition clause.
at this end of streams, there is no stream type: what is important is
the type of data you manipulate.
in fact, stream attributes are kind of double-dispatching
operations... at the light of this explaination, you should re-read
ARM95 13.13, and may better understand them.
so, now you understand this, you may ask yourself if you really need
to use Receive_Socket() or Send_Socket(): they are intended to
programmers writing their own stream attributes... (note that this
could be useful to communicate with a C program through socket streams).
i hope this explaination clarified things a bit and was useful to you
(or others)... language lawyers will surely push it a little bit further.
--
rien
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: TCP/IP Sockets with GNAT.Sockets
2005-05-02 12:11 ` Adrien Plisson
@ 2005-05-02 14:55 ` fabio de francesco
2005-05-02 16:10 ` Adrien Plisson
0 siblings, 1 reply; 4+ messages in thread
From: fabio de francesco @ 2005-05-02 14:55 UTC (permalink / raw)
Adrien Plisson wrote:
> fabio de francesco wrote:
> > Hello,
>
> hello !
>
> > Today is the first time I try to use sockets in Ada programs, even
if I
> > have some practical knowledge of programming with TCP/IP sockets in
C.
> > Because I didn't find any better tutorial on working with
GNAT.Sockets
> > I am relying on comments in file g-socket.ads from GCC/GNAT sources
> > where there is not a complete and detailed coverage of the subject.
> >
> > (1) Do you know any better tutorial?
>
> personnally, no. the GNAT reference manual says:
> "The chapter here simply gives a brief summary of the facilities
> available. The full documentation is found in the spec file for the
> package. The full sources of these library packages, including both
> spec and body, are provided with all GNAT releases."
> so, you can rely on the comments in g-socket.ads (which contains some
> full examples).
>From my message: "...I am relying on comments in file g-socket.ads from
GCC/GNAT sources...". Sorry for my poor English, I know that sometimes
I'm unable to express clearly, but I had already done exactly what you
now suggest.
> also, the behavior is identical to other sockets
> implementation (C, Python, or others) so don't hesitate to read
> manuals for other languages.
I also said I already know how to program with sockets in C.
> the only big difference is in Streams, which is Ada specific...
This is the only problem I wrote I had. I didn't know how to use
Send_Socket() and Receive_Socket() because the specs say they take
"Stream_Element_Array" and "Stream_Element_Offset" as parameters.
If you read g-socket.ads you won't find any usage example either of the
above mentioned functions or related parameters.
> [...]
> > I hadn't too many problems with exchanging messages and everything
> > works. The problem is that I was only able to use Streams for
> > communicating between them and I can't understand at all how to use
> > Receive_Socket() and Send_Socket() because they use
> > "Stream_Element_Array" and "Stream_Element _Offset" in place of
> > Strings. I know that by using Streams they can't communicate with C
> > programs and I've read that Streams are everything but efficient.
>
> streams are not specially inefficient (to the contrary, my dear). the
> problem is that many people do not clearly understand them !
That was what I have found by searching and reading this NG through
Google for help in using them right before posting.
> so let's explain Ada streams:
>
> streams are defined as a tagged record in Ada.Streams, which is to be
> derived in order to implement stream specific behavior: how to send
or
> receive data from stream. Streams define 2 procedures for reading and
> writing data onto them. on this side of streams, data are represented
> as Stream_Element grouped in Stream_Element_Array. a single
> Stream_Element may represent a byte you send over the network for
> example.
>
> at this end of streams, there is no data type: what is important is
> the type of streams you manipulate.
>
> on the other end, you are concerned with data types you read from or
> write to stream, but not with the type of streams. on this end, every
> streams are equal, may it be file, socket, or anything else. this is
> achieved through stream oriented attributes: 'Read, 'Write, 'Input
and
> 'Output. those attributes allow you to read or write a specific data
> type from/to a stream. for example: Integer'Input( S ) will read an
> integer from the stream S (whatever stream type S is). the behavior
of
> those attribute may be overriden through an attribute definition
clause.
>
> at this end of streams, there is no stream type: what is important is
> the type of data you manipulate.
>
> in fact, stream attributes are kind of double-dispatching
> operations... at the light of this explaination, you should re-read
> ARM95 13.13, and may better understand them.
Thank you for this detailed explanation.
> so, now you understand this, you may ask yourself if you really need
> to use Receive_Socket() or Send_Socket(): they are intended to
> programmers writing their own stream attributes... (note that this
> could be useful to communicate with a C program through socket
streams).
This is exactly the problem that I have overcome with the help I've had
from Eric Jacoboni. Both my client and server programs didn't work at
exchanging messages with C programs. After searching the web I
discovered I had to use Receive_Socket() and Send_Socket() in order to
get over that problem.
S : String := "Hello";
SEA : Stream_Element_Array(1..S'Length);
for SEA'Address use S(S'First)'Address;
Last : Stream_Element_Offset;
Send_Socket( Socket, SEA, Last );
This is not exactly what someone can find in a Python or C manual. :-)
You're right about the fact that the fault is mine for not knowing
Streams while a Socket package isn't required to give any explanations
on the usage of a subject that is not so closely related.
Anyway the package authors cover about 350 lines with an procedure
example only using Streams, without ever saying why and when you should
sometimes choose Receive_Socket() and Send_Socket() in place of
Streams.
> i hope this explaination clarified things a bit and was useful to you
> (or others)... language lawyers will surely push it a little bit
further.
>
> --
> rien
Thanks, it helped a lot to make me to understand Streams. I hope this
time I have been able to make myself clear.
fabio de francesco
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: TCP/IP Sockets with GNAT.Sockets
2005-05-02 14:55 ` fabio de francesco
@ 2005-05-02 16:10 ` Adrien Plisson
2005-05-02 17:56 ` Eric Jacoboni
0 siblings, 1 reply; 4+ messages in thread
From: Adrien Plisson @ 2005-05-02 16:10 UTC (permalink / raw)
fabio de francesco wrote:
>>From my message: "...I am relying on comments in file g-socket.ads from
> GCC/GNAT sources...". Sorry for my poor English, I know that sometimes
> I'm unable to express clearly, but I had already done exactly what you
> now suggest.
[...]
> I also said I already know how to program with sockets in C.
i'm sorry if you misunderstood my words: i just wanted to make clear
that you did exactly what you had to do, and that there was no other
way to go.
>>the only big difference is in Streams, which is Ada specific...
(this was just an introduction for the next big paragraph...)(french
style)
[...]
> Thank you for this detailed explanation.
you're welcome !
> This is exactly the problem that I have overcome with the help I've had
> from Eric Jacoboni. Both my client and server programs didn't work at
> exchanging messages with C programs. After searching the web I
> discovered I had to use Receive_Socket() and Send_Socket() in order to
> get over that problem.
that's plain wrong...
the problem is the use of attributes 'Output on arrays which output
array bounds before array data. and since String is an array,
String'Output outputs String bounds before string data. (in Ada you
are no more in C: a string is not delimited by a null character but
has a lower and an upper bound).
those bounds are always getting in the way when:
1. you are not aware of their existence on the stream
2. the reader of the stream is not an ada program.
anyway, you can get rid of those bounds by using 'Read and 'Write
instead of 'Input and 'Output. BUT you have to know that using 'Read
on unconstrained arrays (especially on String) is... well... A Bad
Thing(tm). (i'm not even sure it works).
you should note that the problem is the same in C: when reading a
string (sorry an array of char) from a socket, you don't know its
length. how can you say you read the whole string, and not a sub-part,
or worst, the whole string plus the beginning of the following data ?
if you can overcome this problem in C, rest assured you can overcome
it in Ada...
(the exact default behavior for stream attributes is detailed in ARM95
13.13.2: this includes the behavior for array bounds, type
discriminants, tags...)
> S : String := "Hello";
> SEA : Stream_Element_Array(1..S'Length);
> for SEA'Address use S(S'First)'Address;
> Last : Stream_Element_Offset;
> Send_Socket( Socket, SEA, Last );
(i'm sorry i'm gonna be a bit rude) beuark !
this is implementation dependant:
- what if Character'Size /= Stream_Element'Size ?
- what if the memory organization of Stream_Element_Array does not
match the one for a String ?
(i'm not sure overlays are not a recommended practice, but i may be wrong)
you'd better write this:
declare
Socket : Socket_Type;
Channel : Stream_Access;
begin
-- open your socket here, then...
Channel := Stream( Socket );
String'Write( Channel, "Hello" );
-- close your socket here...
end;
> This is not exactly what someone can find in a Python or C manual. :-)
i won't put it in an Ada manual either !!
> You're right about the fact that the fault is mine for not knowing
> Streams while a Socket package isn't required to give any explanations
> on the usage of a subject that is not so closely related.
it is not your fault, it is just that manuals/tutorials don't tell
much about streams. and don't worry, it took me a long time to
understand streams. i just don't want people to encounter the same
problems i had with them, that's why i always try to "demystify" streams.
> Anyway the package authors cover about 350 lines with an procedure
> example only using Streams, without ever saying why and when you should
> sometimes choose Receive_Socket() and Send_Socket() in place of
> Streams.
maybe because you just don't need them ! or only need them when you
plainly understand what's behind them.
> Thanks, it helped a lot to make me to understand Streams. I hope this
> time I have been able to make myself clear.
you already made yourself clear...
--
rien
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: TCP/IP Sockets with GNAT.Sockets
2005-05-02 16:10 ` Adrien Plisson
@ 2005-05-02 17:56 ` Eric Jacoboni
2005-05-02 18:30 ` Poul-Erik Andreasen
0 siblings, 1 reply; 4+ messages in thread
From: Eric Jacoboni @ 2005-05-02 17:56 UTC (permalink / raw)
In article <42765108$0$22419$ba620e4c@news.skynet.be>, Adrien Plisson
<aplisson-news@stochastique.net> wrote:
> > S : String := "Hello";
> > SEA : Stream_Element_Array(1..S'Length);
> > for SEA'Address use S(S'First)'Address;
> > Last : Stream_Element_Offset;
> > Send_Socket( Socket, SEA, Last );
>
> (i'm sorry i'm gonna be a bit rude) beuark !
Agree. It's not the sort of things i expected to write with Ada... But,
that's the only code that fits my needs.
> this is implementation dependant:
> - what if Character'Size /= Stream_Element'Size ?
> - what if the memory organization of Stream_Element_Array does not
> match the one for a String ?
For the second point, Stream_Element_Array is defined as an array of
Stream_Element, so i suppose it match the memory organization of a
String, isn't it ?
> you'd better write this:
>
> declare
> Socket : Socket_Type;
> Channel : Stream_Access;
> begin
> -- open your socket here, then...
> Channel := Stream( Socket );
>
> String'Write( Channel, "Hello" );
> -- close your socket here...
> end;
Have you tried this code with a server not Ada aware? Have you tried to
exchange messages with, say, a POP3 server? (to send and to read) I've
tried to use Streams for that, but i never succeeded to make it work...
If a cleaner solution exists, why the hell cannot we find _any_
example?
--
jaco
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: TCP/IP Sockets with GNAT.Sockets
2005-05-02 17:56 ` Eric Jacoboni
@ 2005-05-02 18:30 ` Poul-Erik Andreasen
2005-05-02 19:10 ` Simon Wright
0 siblings, 1 reply; 4+ messages in thread
From: Poul-Erik Andreasen @ 2005-05-02 18:30 UTC (permalink / raw)
Eric Jacoboni wrote:
> In article <42765108$0$22419$ba620e4c@news.skynet.be>, Adrien Plisson
> <aplisson-news@stochastique.net> wrote:
>
>
>
>>>S : String := "Hello";
>>>SEA : Stream_Element_Array(1..S'Length);
>>>for SEA'Address use S(S'First)'Address;
>>>Last : Stream_Element_Offset;
>>>Send_Socket( Socket, SEA, Last );
>>
>>(i'm sorry i'm gonna be a bit rude) beuark !
>
>
> Agree. It's not the sort of things i expected to write with Ada... But,
> that's the only code that fits my needs.
>
>
>>this is implementation dependant:
>>- what if Character'Size /= Stream_Element'Size ?
>>- what if the memory organization of Stream_Element_Array does not
>>match the one for a String ?
>
>
> For the second point, Stream_Element_Array is defined as an array of
> Stream_Element, so i suppose it match the memory organization of a
> String, isn't it ?
>
>
>>you'd better write this:
>>
>>declare
>> Socket : Socket_Type;
>> Channel : Stream_Access;
>>begin
>> -- open your socket here, then...
>> Channel := Stream( Socket );
>>
>> String'Write( Channel, "Hello" );
>> -- close your socket here...
>>end;
>
>
> Have you tried this code with a server not Ada aware? Have you tried to
> exchange messages with, say, a POP3 server? (to send and to read) I've
> tried to use Streams for that, but i never succeeded to make it work...
> If a cleaner solution exists, why the hell cannot we find _any_
> example?
>
I have, actually i am using it rigth now and i works. however If the
other end of the socket is a C-style server it will probely demand
somthing like the following:
String'Write( Channel, "Hello" & character'first);
when i read i read characters and stop when i reach character'first.
Here is a fixed string sulution
declare
Channel := Stream( Socket );
Word : string(1.. max_word);
counter : natural := 1
begin
loop
word(counter) := Character'Input (Channel);
exit when word(counter) = Character'First;
counter := counter + 1;
end loop;
-- her do what you have to do with Word(1..(counter -1))
end;
BTW my C-couterpart program dosn't seems to have anything against
String'Output( Channel, "Hello" & character'first) ?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: TCP/IP Sockets with GNAT.Sockets
2005-05-02 18:30 ` Poul-Erik Andreasen
@ 2005-05-02 19:10 ` Simon Wright
2005-05-03 13:00 ` Poul-Erik Andreasen
0 siblings, 1 reply; 4+ messages in thread
From: Simon Wright @ 2005-05-02 19:10 UTC (permalink / raw)
Poul-Erik Andreasen <poulerik@pea.dk> writes:
> BTW my C-couterpart program dosn't seems to have anything against
> String'Output( Channel, "Hello" & character'first) ?
Well, that _ought_ to send
(a) 4 bytes == 1, which is the lower index of the string
(b) 4 bytes == 6, which is the upper index of the string
(c) the null-terminated string.
So it depends what your C-counterpart did with those strange
characers.
Why do you say Character'First & not ASCII.NUL?
If you don't want to include the bounds, use 'Write.
There's nothing wrong with streams, but you do have to know exactly
what the language requires the compiler to do!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: TCP/IP Sockets with GNAT.Sockets
2005-05-02 19:10 ` Simon Wright
@ 2005-05-03 13:00 ` Poul-Erik Andreasen
2005-05-04 8:01 ` Character'First, ASCII.NUL and others (Was: Re: TCP/IP Sockets with GNAT.Sockets) Adrien Plisson
0 siblings, 1 reply; 4+ messages in thread
From: Poul-Erik Andreasen @ 2005-05-03 13:00 UTC (permalink / raw)
Simon Wright wrote:
> Poul-Erik Andreasen <poulerik@pea.dk> writes:
>
>
>>BTW my C-couterpart program dosn't seems to have anything against
>>String'Output( Channel, "Hello" & character'first) ?
>
>
> Well, that _ought_ to send
>
> (a) 4 bytes == 1, which is the lower index of the string
> (b) 4 bytes == 6, which is the upper index of the string
> (c) the null-terminated string.
> So it depends what your C-counterpart did with those strange
> characers.
It probely just trow them away, i think the reson why is not a problem
is that besides being zero terminated the the messages that i sent are
requered to start with '$', Anyway i will, ofcourse change to
string'write
>
> Why do you say Character'First & not ASCII.NUL?
Not for any partikulari reason.
When i started developing job i tried with ASCII.NUL
things didn't work out(surely for som other reason);
they did when i first was using character'first.
(also surely for som other reason);
Are there any reason why ASCII.NUL should be better;
ASCII.NUL are defined as Character'First;
> If you don't want to include the bounds, use 'Write.
I will
> There's nothing wrong with streams, but you do have to know exactly
> what the language requires the compiler to do!
Therefor this is realy a nice thread :-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Character'First, ASCII.NUL and others (Was: Re: TCP/IP Sockets with GNAT.Sockets)
2005-05-03 13:00 ` Poul-Erik Andreasen
@ 2005-05-04 8:01 ` Adrien Plisson
2005-05-04 13:40 ` Poul-Erik Andreasen
0 siblings, 1 reply; 4+ messages in thread
From: Adrien Plisson @ 2005-05-04 8:01 UTC (permalink / raw)
Poul-Erik Andreasen wrote:
> When i started developing job i tried with ASCII.NUL
> things didn't work out(surely for som other reason);
> they did when i first was using character'first.
> (also surely for som other reason);
>
> Are there any reason why ASCII.NUL should be better;
Character'First do not describe the NUL character. i mean, it is the
NUL character, but you have to know the implementation details of type
Character to see that it's first element is the NUL character.
ASCII.NUL states explicitly that you are using the NUL character,
that's why its use should be better.
anyway, the package ASCII is described in ARM95 J.5, that means it is
part of "Obsolescent Features". as said in the ARM, "Use of these
features is not recommended in newly written programs.". so it is
better than Character'First, but there exists a better way to write this.
the better way is the use of Ada.Characters.Latin_1, which defines a
constant NUL describing the NUL character. unfortunately, the package
name is long, so you may have to write a use clause or a rename.
with Ada.Text_IO,
Ada.Characters.Latin_1;
procedure Test is
-- see comments below
use Ada.Characters.Latin_1;
package ASCII renames Ada.Characters.Latin_1;
package Characters renames Ada.Characters.Latin_1;
begin
Ada.Text_IO.Put( Ada.Characters.Latin_1.NUL ); -- a bit long
Ada.Text_IO.Put( NUL ); -- a bit short, NUL what ?
-- NUL Character ? not sure...
Ada.Text_IO.Put( ASCII.NUL ); -- not recommended, there is
-- a risk of confusion
Ada.Text_IO.Put( Characters.NUL ); -- this seems better !
end Test;
besides all this, when looking at Ada.Characters.Latin_1, we see that
NUL is defined this way :
NUL : constant Character := Character'Val(0);
so if you just need NUL and want to avoid declarations, you may use
Character'Val(0), which describes the NUL character better than
Character'First.
--
rien
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Character'First, ASCII.NUL and others (Was: Re: TCP/IP Sockets with GNAT.Sockets)
2005-05-04 8:01 ` Character'First, ASCII.NUL and others (Was: Re: TCP/IP Sockets with GNAT.Sockets) Adrien Plisson
@ 2005-05-04 13:40 ` Poul-Erik Andreasen
0 siblings, 0 replies; 4+ messages in thread
From: Poul-Erik Andreasen @ 2005-05-04 13:40 UTC (permalink / raw)
Adrien Plisson wrote:
> Poul-Erik Andreasen wrote:
>
>> When i started developing job i tried with ASCII.NUL
>> things didn't work out(surely for som other reason);
>> they did when i first was using character'first.
>> (also surely for som other reason);
>
> >
>
>> Are there any reason why ASCII.NUL should be better;
>
>
> Character'First do not describe the NUL character. i mean, it is the NUL
> character, but you have to know the implementation details of type
> Character to see that it's first element is the NUL character.
>
> ASCII.NUL states explicitly that you are using the NUL character, that's
> why its use should be better.
>
> anyway, the package ASCII is described in ARM95 J.5, that means it is
> part of "Obsolescent Features". as said in the ARM, "Use of these
> features is not recommended in newly written programs.". so it is better
> than Character'First, but there exists a better way to write this.
>
> the better way is the use of Ada.Characters.Latin_1, which defines a
> constant NUL describing the NUL character. unfortunately, the package
> name is long, so you may have to write a use clause or a rename.
>
> with Ada.Text_IO,
> Ada.Characters.Latin_1;
> procedure Test is
> -- see comments below
> use Ada.Characters.Latin_1;
> package ASCII renames Ada.Characters.Latin_1;
> package Characters renames Ada.Characters.Latin_1;
>
> begin
> Ada.Text_IO.Put( Ada.Characters.Latin_1.NUL ); -- a bit long
>
> Ada.Text_IO.Put( NUL ); -- a bit short, NUL what ?
> -- NUL Character ? not sure...
>
> Ada.Text_IO.Put( ASCII.NUL ); -- not recommended, there is
> -- a risk of confusion
>
> Ada.Text_IO.Put( Characters.NUL ); -- this seems better !
> end Test;
>
> besides all this, when looking at Ada.Characters.Latin_1, we see that
> NUL is defined this way :
>
> NUL : constant Character := Character'Val(0);
>
> so if you just need NUL and want to avoid declarations, you may use
> Character'Val(0), which describes the NUL character better than
> Character'First.
>
point taken
thanks
Poul-Erik Andreasen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-05-15 2:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-15 2:42 Character'First, ASCII.NUL and others (Was: Re: TCP/IP Sockets with GNAT.Sockets) Frank Beard
[not found] <mailman.112.1115585537.24457.comp.lang.ada@ada-france.org>
2005-05-09 20:59 ` Manuel G. R.
-- strict thread matches above, loose matches on Subject: below --
2005-05-02 2:42 TCP/IP Sockets with GNAT.Sockets fabio de francesco
2005-05-02 12:11 ` Adrien Plisson
2005-05-02 14:55 ` fabio de francesco
2005-05-02 16:10 ` Adrien Plisson
2005-05-02 17:56 ` Eric Jacoboni
2005-05-02 18:30 ` Poul-Erik Andreasen
2005-05-02 19:10 ` Simon Wright
2005-05-03 13:00 ` Poul-Erik Andreasen
2005-05-04 8:01 ` Character'First, ASCII.NUL and others (Was: Re: TCP/IP Sockets with GNAT.Sockets) Adrien Plisson
2005-05-04 13:40 ` Poul-Erik Andreasen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox