Program error from assignment?? 
Author Message
 Program error from assignment??

<snip>

Quote:

>So now this turns into an "accessability level" question. The object that
is
>pointed to is declared in the declaration section of the main routine. It
>exists the entire program. I don't understand the exact rules on
accessability
>levels, but in my book I should *never* fail an accessability check with
this
>object. The access type is declared in a package spec.

The probelem with that reasoning is that there is nothing which
distibguishes your "main program" from any other library procedure which
could be called from another "ain" progeam.  Thus, the lifetime of the
object in question is only diring the execution of the subprogram.in which
it is declared.

Hope this helps,

David C. Hoos, Sr.



Sun, 07 Jan 2001 03:00:00 GMT  
 Program error from assignment??

Quote:

> Program_Error can happen on this assignment when the accessability level of
> the source pointer's object is deeper than that of the target object's type.
> That's so I can't keep around a pointer to an object after it goes away. Fair
> enough.

> So now this turns into an "accessability level" question. The object that is
> pointed to is declared in the declaration section of the main routine. It
> exists the entire program. I don't understand the exact rules on accessability
> levels, but in my book I should *never* fail an accessability check with this
> object. The access type is declared in a package spec.

> T.E.D.

The compiler doesn't know that this routine is your main routine, so
it assumes it could be called from some other routine; then the
accessibility check makes sense. (uh oh; is this an advantage for C
"main"? :).

You have two options:

1) Declare the object in a library level package (I usually call such
a package main_aux.ads or some such).

2) Use 'Unchecked_Access. This situation is pretty much what
Unchecked_Access is for; you are telling the compiler that you are
smarter than it is (well, at least you promise not to use the pointer
after the object goes out of scope :).

-- Stephe



Sun, 07 Jan 2001 03:00:00 GMT  
 Program error from assignment??


Quote:


>> OK. I give up.

>> I have the following code:
>.
>.
>.
>> The problem is that I'm getting a Program_Error on the second assignment
at
>> runtime. What could cause that?

>OK. Since everyone seems to be completely speechless :-), here's what I've
>found out so far:

>Program_Error can happen on this assignment when the accessability level of
>the source pointer's object is deeper than that of the target object's
type.
>That's so I can't keep around a pointer to an object after it goes away.
Fair
>enough.

>So now this turns into an "accessability level" question. The object that
is
>pointed to is declared in the declaration section of the main routine. It
>exists the entire program. I don't understand the exact rules on
accessability
>levels, but in my book I should *never* fail an accessability check with
this
>object. The access type is declared in a package spec.

OK, you almost got it right. Yes, it is a problem with dynamic accessibility
level.

Now remember, a type declared in a library package is at accessibility level
0, while an object declared in a library *procedure* (even the one used as
the main program) is at accessibility level 1.

Remember that the main program is a regular procedure in Ada. For example, a
library package could declare tasks that would in turn call the main program
as a regular procedure...

--
----------------------------------------------------------------------------

      Visit Adalog's web site at http://perso.wanadoo.fr/adalog



Sun, 07 Jan 2001 03:00:00 GMT  
 Program error from assignment??
<<So now this turns into an "accessability level" question. The object that is
pointed to is declared in the declaration section of the main routine. It
exists the entire program. I don't understand the exact rules on accessability
levels, but in my book I should *never* fail an accessability check with this
object. The access type is declared in a package spec.

This is an obvious violation of the accessibility rules, since the package
spec is at a higher accessibility level. You know that it is OK, but there
is no structural guarantee.



Sun, 07 Jan 2001 03:00:00 GMT  
 Program error from assignment??

: ...
: I tried this with a second compiler with the same result (Program_Error). So
: it looks like the language does define the main program to be at a lower
: accessability level than package specs. Personally I find that a bit weird,
: but I'm guessing the rationale is as follows:

The main subprogram is just like any other subprogram in Ada.
It can be recursive, called from multiple tasks, etc.
All subprograms are at a deeper level than the enclosing scope.

And even without weirdness like calling the main subprogram recursively,
it is definitely the case that the program as a whole is not done
just because the main subprogram returns.  Program termination does
not occur until all the library-level tasks terminate.  In fact,
it is possible for the main subprogram's body to be "null" and
have all of the interesting work happen in library-level tasks,
after the main subprogram returns.

: ...
:   2  Move the object declaration into a package spec somewhere. That gives it
: the exact same accessability level as the type. I like this solution better,
: even if the package has to be created specially for the job. (package
: Make_It_Run_Dammit is ...)

This is the right solution.

: T.E.D.

--

Intermetrics, Inc.  Burlington, MA  USA



Mon, 08 Jan 2001 03:00:00 GMT  
 Program error from assignment??
T.E.D. said

<<My code could, theoretically, pass the new access value for the object into a
task (which had also with'ed the package that declares the access type). Then
my main procedure where the object is declared could, theoretically, end. The
program will continue to hang around as long as the task doesn't end too.

The compiler vendor could have, theoretically, decided to pop the stack for
the main procedure even though the program isn't quite done yet. I would have
figured the more natural implementation is that the tasks (and their main
stacks) are declared on the main procedure's stack along with all its
variables, but it doesn't HAVE to be done that way.

no, no. You needn't hypothesize such strange things. Just realize that
there is nothing special about the main program, it is just a procedure
that anyone could call from anywhere.



Mon, 08 Jan 2001 03:00:00 GMT  
 Program error from assignment??
T.E.D. said

<<You are one sick puppy for even thinking of that!
:-)

Actually, I have seen more than one example of recursive main programs
in Ada. There is nothing to prevent it, and it is perfectly reasona ble
to structure a program this way if it makes sense.



Mon, 08 Jan 2001 03:00:00 GMT  
 Program error from assignment??



Quote:


>> Remember that the main program is a regular procedure in Ada. For
example, a
>> library package could declare tasks that would in turn call the main
program
>> as a regular procedure...

>(shudder)

>You are one sick puppy for even thinking of that!
>:-)

Not at all, think about how Unix starts. Single user mode, then starting
severall tasks that call the main program will turn the system into
multi-user mode...
--
----------------------------------------------------------------------------

      Visit Adalog's web site at http://perso.wanadoo.fr/adalog


Mon, 08 Jan 2001 03:00:00 GMT  
 Program error from assignment??
"So now this turns into an "accessability level" question. The object that is
  pointed to is declared in the declaration section of the main routine. It
  exists the entire program. I don't understand the exact rules on accessability
  levels, but in my book I should *never* fail an accessability check with this
  object. The access type is declared in a package spec."

...and don't forget that there is nothing stating that the main procedure
will outlive other parts of the system (e.g. other tasks could continue
to run).

If you don't want the check made, try using pragma suppress.

Dale



Mon, 08 Jan 2001 03:00:00 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Runtime Error R6001 Nul Pointer Assignment

2. C compilation errors with reverse assignment

3. Array assignment error

4. Verilog error? (non blocking assignments + assign statement)

5. Newbie - error with 'Limited Type' assignment

6. I NEED HELP WITH AN ERROR I GET IN THIS ASSIGNMENT I AM CLOSE TO FINISHING

7. CVF6.6B Compiler Error: Null Pointer Assignment In Type Declaration

8. array assignment error in F90(under Java Native Interface)

9. Empty variable assignment error?

10. list comprehensions value assignment syntax error

11. No Assignment in Conditional/PROPOSAL: Assignment expression

12. Memo assignment locking program?

 

 
Powered by phpBB® Forum Software