Cannot use NULL as identifier? 
Author Message
 Cannot use NULL as identifier?

I've written a small program that parses the contents of different
directories and searches for duplicate files.

I have an assignment that reads

FilePath : constant string := "tesfile.xxx" & ASCII.NULL;

Now, the GNAT compiler on Linux gives me the error
"reserved word NULL cannot be used as identifier "

Now, I'm using the text_io and gnat.os_lib libraries to compile this, so
I'm assuming that os_lib makes an allowance for this. However, I could be
mistaken. I ripped the above code fragement from a website, and the
website (the Big Book of Linux Ada programming) doesnt appear to  indicate
that theres a problem with this. (Of course I probably overlooked
something.)

I'm also searching through "Programming in Ada95"(Barnes) trying to find
info on this error.

Any tips or pointers would be helpful.

Thanks.

McDoobie



Sun, 16 Nov 2003 21:04:32 GMT  
 Cannot use NULL as identifier?

Quote:

>FilePath : constant string := "tesfile.xxx" & ASCII.NULL;

>Now, the GNAT compiler on Linux gives me the error
>"reserved word NULL cannot be used as identifier "

OK. There are 3 issues here:

1)  "null" is a keyword. It is used for "null" statements, and as a default
value for access objects. You can't create a variable with that name any more
than you can create a variable named "if".

2) The value you are looking for is "ASCII.NUL", not "ASCII.NULL". (A quick
check of the package specification would have told you this.

3) The package ASCII is obsolescent, so I wouldn't use it in new code if I were
you. You should be using "Ada.Characters.Latin_1.Nul".

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html



Sun, 16 Nov 2003 21:22:23 GMT  
 Cannot use NULL as identifier?
Quote:

<snip>
> FilePath : constant string := "tesfile.xxx" & ASCII.NULL;

> Now, the GNAT compiler on Linux gives me the error
> "reserved word NULL cannot be used as identifier "

<snap>

ASCII.NUL; -- one 'L', because null is reserved.

Note that package ASCII is declared as obsolete in Ada 95.

--
hwyl/cheers,
Philip Anderson
Alenia Marconi Systems
Cwmbran, Cymru/Wales



Sun, 16 Nov 2003 21:27:54 GMT  
 Cannot use NULL as identifier?
This is perhaps not the best and most efficient solution, but it works:

with Ada.Characters.Latin_1;
...
...
FilePath : constant string := "tesfile.xxx" & Ada.Characters.Latin_1.Nul;

Quote:

>I've written a small program that parses the contents of different
>directories and searches for duplicate files.

>I have an assignment that reads

>FilePath : constant string := "tesfile.xxx" & ASCII.NULL;

>Now, the GNAT compiler on Linux gives me the error
>"reserved word NULL cannot be used as identifier "

>Now, I'm using the text_io and gnat.os_lib libraries to compile this, so
>I'm assuming that os_lib makes an allowance for this. However, I could be
>mistaken. I ripped the above code fragement from a website, and the
>website (the Big Book of Linux Ada programming) doesnt appear to  indicate
>that theres a problem with this. (Of course I probably overlooked
>something.)

>I'm also searching through "Programming in Ada95"(Barnes) trying to find
>info on this error.

>Any tips or pointers would be helpful.

>Thanks.

>McDoobie




Sun, 16 Nov 2003 21:33:51 GMT  
 Cannot use NULL as identifier?
ASCII is an obsolete package, use Ada.Characters.Latin_1 instead.
The other problem you have is 'NULL' with 2 'L' characters. So what
you need is:

  FilePath : constant string := "tesfile.xxx" & Ada.Characters.Latin_1.Nul;

Alternatively, it looks like you're trying to do things in a 'C'-way,
or interface with some 'C' routines, so have a look at Interfaces.C (and
maybe Interfaces.C.Strings) to find routines to create nul-terminated
strings.

Enjoy!


Quote:
> I've written a small program that parses the contents of different
> directories and searches for duplicate files.

> I have an assignment that reads

> FilePath : constant string := "tesfile.xxx" & ASCII.NULL;

> Now, the GNAT compiler on Linux gives me the error
> "reserved word NULL cannot be used as identifier "

> Now, I'm using the text_io and gnat.os_lib libraries to compile this, so
> I'm assuming that os_lib makes an allowance for this. However, I could be
> mistaken. I ripped the above code fragement from a website, and the
> website (the Big Book of Linux Ada programming) doesnt appear to  indicate
> that theres a problem with this. (Of course I probably overlooked
> something.)

> I'm also searching through "Programming in Ada95"(Barnes) trying to find
> info on this error.

> Any tips or pointers would be helpful.

> Thanks.

> McDoobie




Sun, 16 Nov 2003 21:32:34 GMT  
 Cannot use NULL as identifier?
May be ASCII.NUL is best than ASCII.NULL

McDoobie a crit :

Quote:
> I've written a small program that parses the contents of different
> directories and searches for duplicate files.

> I have an assignment that reads

> FilePath : constant string := "tesfile.xxx" & ASCII.NULL;

> Now, the GNAT compiler on Linux gives me the error
> "reserved word NULL cannot be used as identifier "

> Now, I'm using the text_io and gnat.os_lib libraries to compile this, so
> I'm assuming that os_lib makes an allowance for this. However, I could be
> mistaken. I ripped the above code fragement from a website, and the
> website (the Big Book of Linux Ada programming) doesnt appear to  indicate
> that theres a problem with this. (Of course I probably overlooked
> something.)

> I'm also searching through "Programming in Ada95"(Barnes) trying to find
> info on this error.

> Any tips or pointers would be helpful.

> Thanks.

> McDoobie




Sun, 16 Nov 2003 21:58:16 GMT  
 Cannot use NULL as identifier?
Null is a reserved word in Ada - used as a null statement and as a value for
access types, etc. You can't use it as an identifier.

What you probably want is ASCII.Nul - notice only one 'l'.

Also, unless you are interfacing to some C/C++ routines, you do not need to
terminate strings with Nul. You are much better off using the attributes
'First, 'Last, 'Range, etc. along with the string handling routines you'll
find in Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Bounded,
Ada.Strings.Unbounded. (My personal favorite is to use Ada.Strings.Unbounded
for just about everything. It will have some speed/space penalties over
fixed strings, but you'd really have to have an intense application to start
noticing the difference.)

BTW, you probably don't want to use the package ASCII since it is falling
out of vogue and may eventually go away. More appropriately, you should use
Ada.Characters.Latin_1 which also contains a constant called "Nul".

If you have not done so already, you will want to get hold of an Ada95
Reference Manual (plenty of electronic sources). To really get all the
benefits of Ada, you'll want to look over all the appendices and at least be
cognizant of the language defined packages and what they contain. That way,
when you need a resource (like character constants, math routines, string
manipulation, etc.) you'll at least have a vague memory of what is available
and know where to look for more help. I repeatedly find myself in there
digging up routines to leverage someone else's work! :-)

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution

Web:      http://www.mcondic.com/


Quote:
> I've written a small program that parses the contents of different
> directories and searches for duplicate files.

> I have an assignment that reads

> FilePath : constant string := "tesfile.xxx" & ASCII.NULL;

> Now, the GNAT compiler on Linux gives me the error
> "reserved word NULL cannot be used as identifier "

> Now, I'm using the text_io and gnat.os_lib libraries to compile this, so
> I'm assuming that os_lib makes an allowance for this. However, I could be
> mistaken. I ripped the above code fragement from a website, and the
> website (the Big Book of Linux Ada programming) doesnt appear to  indicate
> that theres a problem with this. (Of course I probably overlooked
> something.)

> I'm also searching through "Programming in Ada95"(Barnes) trying to find
> info on this error.

> Any tips or pointers would be helpful.

> Thanks.

> McDoobie




Sun, 16 Nov 2003 21:52:18 GMT  
 Cannot use NULL as identifier?

Quote:

> Note that package ASCII is declared as obsolete in Ada 95.

It is obsolescent and not obsolete.

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"



Mon, 17 Nov 2003 00:40:17 GMT  
 Cannot use NULL as identifier?

Quote:

> ASCII.NUL; -- one 'L', because null is reserved.

Correct observation, wrong explanation.

The official character name according to ANSI X3.4-1986 is indeed
'NULL', but package ASCII uses the official abbreviations, and 'NULL'
becomes 'NUL'.



Mon, 17 Nov 2003 04:52:34 GMT  
 Cannot use NULL as identifier?

Quote:
-----Original Message-----

> 3) The package ASCII is obsolescent, so I wouldn't use
> it in new code if I were you. You should be using
> "Ada.Characters.Latin_1.Nul".

As Ben Brosgol pointed out, ASCII was obsolescent before
the ASCII standard was expanded to include characters 128
through 255.  So, the odds of ASCII becoming obsolete are
slim to none.  So, I wouldn't worry too much about whether
or not to use ASCII.

Even if it does become obsolete, it is a relatively
simply global substitute to replace "ASCII" with
"Ada.Characters.Latin_1.Nul", or do a library level rename.
Besides "Ada.Characters.Latin_1.Nul" being ugly to look at,
if for nothing else, I will continue to use ASCII to avoid
the lame analogies of Latin to Ada made by some of the C++
hacks ("A dead language for a dead language").

Frank



Mon, 17 Nov 2003 05:45:48 GMT  
 Cannot use NULL as identifier?

Quote:
> BTW, you probably don't want to use the package ASCII since it is falling
> out of vogue and may eventually go away.

The obsolescent features, including package ASCII, will never go away.

- Bob



Mon, 17 Nov 2003 10:09:24 GMT  
 Cannot use NULL as identifier?

Quote:

> Null is a reserved word in Ada - used as a null statement and as a value
> for access types, etc. You can't use it as an identifier.

> What you probably want is ASCII.Nul - notice only one 'l'.

> Also, unless you are interfacing to some C/C++ routines, you do not need
> to terminate strings with Nul. You are much better off using the
> attributes
> 'First, 'Last, 'Range, etc. along with the string handling routines
> you'll
> find in Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Bounded,
> Ada.Strings.Unbounded. (My personal favorite is to use
> Ada.Strings.Unbounded for just about everything. It will have some
> speed/space penalties over fixed strings, but you'd really have to have
> an intense application to start noticing the difference.)

> BTW, you probably don't want to use the package ASCII since it is
> falling out of vogue and may eventually go away. More appropriately, you
> should use Ada.Characters.Latin_1 which also contains a constant called
> "Nul".

> If you have not done so already, you will want to get hold of an Ada95
> Reference Manual (plenty of electronic sources). To really get all the
> benefits of Ada, you'll want to look over all the appendices and at
> least be cognizant of the language defined packages and what they
> contain. That way, when you need a resource (like character constants,
> math routines, string manipulation, etc.) you'll at least have a vague
> memory of what is available and know where to look for more help. I
> repeatedly find myself in there digging up routines to leverage someone
> else's work! :-)

> MDC
> --
> Marin David Condic Senior Software Engineer Pace Micro Technology
> Americas    www.pacemicro.com Enabling the digital revolution e-Mail:  


Thanks for your reply. I have duly noted the difference between 'NUL' and
'NULL' thanks to the many replies pointing out that goof up. Also, I will be
spending some time exploring the Latin_1 package in detail, as well as
exploring the internals of the Ada system much more thoroughly.
I've recently purchased an Ada textbook, so I should proceed much more
rapidly now.

And yes, I was interfacing with the GNU glibc libraries. glibc 2.2 to be exact.

I wonder if it would make more sense to just put all my glibc interfaces
into an Ada package and then use them that way. However, I'm also
aware that there are Posix bindings already available, and so I'm tempted to
say that it would make more sense to use those instead. However, as I am
relatively inexperienced in the whole OOP paradigm (coming from a C and
x86 ASM background) I cant yet say for sure what the best route would be.

Back to the books I guess. ;->

Thanks again for all the replies.

McDoobie



Mon, 17 Nov 2003 18:49:21 GMT  
 Cannot use NULL as identifier?
%<

Quote:
> It is obsolescent and not obsolete.

What's the difference ? I'm sorry to say that this is one subtle part
of the english language that I havn't grasped yet.

--

Mida Systemutveckling AB                          http://www.mida.se
Box 64, S-732 22 ARBOGA, SWEDEN
Phone: +46-(0)589-89808   Fax: +46-(0)589-89809



Mon, 17 Nov 2003 19:49:17 GMT  
 Cannot use NULL as identifier?
"Obsolescent" means "becoming obsolete."
The "-cent" suffix is used on lots of words -- e.g.,
"nascent" means "being born,"  etc.


Quote:

> %<
> > It is obsolescent and not obsolete.

> What's the difference ? I'm sorry to say that this is one subtle part
> of the english language that I havn't grasped yet.

> --

> Mida Systemutveckling AB                          http://www.mida.se
> Box 64, S-732 22 ARBOGA, SWEDEN
> Phone: +46-(0)589-89808   Fax: +46-(0)589-89809



Mon, 17 Nov 2003 20:30:02 GMT  
 Cannot use NULL as identifier?

Quote:

> "Obsolescent" means "becoming obsolete."
> The "-cent" suffix is used on lots of words -- e.g.,
> "nascent" means "being born,"  etc.




> > %<
> > > It is obsolescent and not obsolete.

> > What's the difference ? I'm sorry to say that this is one subtle part
> > of the english language that I havn't grasped yet.

Ahh, thank you for enlighting me!

--

Mida Systemutveckling AB                          http://www.mida.se
Box 64, S-732 22 ARBOGA, SWEDEN
Phone: +46-(0)589-89808   Fax: +46-(0)589-89809



Mon, 17 Nov 2003 21:33:37 GMT  
 
 [ 54 post ]  Go to page: [1] [2] [3] [4]

 Relevant Pages 

1. identifiers vs. IDENTIFIERS

2. CALL, identifier-2, and address-identifiers

3. Exclude Nulls (in Key definition): what is Null?

4. Null Record is not always Null

5. NULL statements, NULL values, and teaching

6. win32com support for NULL bstr, NULL com object

7. Null pointer assignment when using BSS segment

8. Null pointer assignment when using BSS

9. Null pointer assignment when using BSS segment

10. Serial communication using null modem cable

11. How to pass NULL to a DLL using DynWin

12. Passing Nulls to Access using ODBC

 

 
Powered by phpBB® Forum Software