tags:

views:

78

answers:

2

I am a beginner in Ada and I have come across a piece of code which is shown below:

                   procedure Null_Proc is
                   begin
                    null;
                   end;

Now as per my knowledge the procedure in Ada doesn't return anything. My doubt is what does this procedure Null_proc do? I mean I am not clear with the definition of the procedure.

+3  A: 

It does nothing.

It might be useful when a procedure must be called but nothing must be done; otherwise, it has little value. (I am working from memory; I assume that Ada does allow functions or procedures as parameters to other functions - in terms of C, pointers to functions.)

Jonathan Leffler
@Jonathan Leffler ..So when u convert this same procedure to some function in C,we would just write as: void Null_Proc { }Am i right?
maddy
@Maddy: yes - almost. The C would be `void Null_Proc(void) { }`, of course, but that's a matter of detailed syntax rather than the concept.
Jonathan Leffler
@Jonathan Leffler..Thanks a lot
maddy
@Jonathan Leffler....procedure Lowest_Level is new GP_Lowest_Level( Integer );Does this mean that Lowest_Level is another procedure which shares the same instance of GP_Lowest_Level procedure already defined?
maddy
@maddy - This deserves a new question!"procedure Lowest_Level is new GP_Lowest_Level( Integer );" - this is a generic subprogram instantiation. It's similar to a C++ template function or a C macro, and most compilers will implement it by creating a new code body. However it's done, it behaves like a new instance.
Simon Wright
@Jonathan Leffler - Functions and procedures became allowable subprogram parameters in Ada 95 through the use of access-to-subprogram types (i.e. roughly analogous to a typedef), and in the Ada 2005 language revision could be directly supplied via anonymous access-to-subprogram types (http://en.wikibooks.org/wiki/Ada_Programming/Types/access#Anonymous_access_to_Subprogram). Just an FYI.
Marc C
@Marc C: That's true. However, even with old Ada (83) just about every compiler allowed some way to get the address of a routine to pass to C callbacks. I wrote several null routines myself for just that purpose.
T.E.D.
@Marc C: thanks for the extra information - also thanks to T.E.D.
Jonathan Leffler
+2  A: 

I've been known to write main routines that way when all the "real code" was in the withed packages. This is particularly likely if your program uses tasking, as the main routine cannot accept rendezvous like a task can, so it often ends up with nothing useful to do. Your entire program will stay active until all tasks complete, so the main routine really doesn't have to do anything.

Another possible use would be for implementing some kind of default routine to supply to callbacks.

T.E.D.
@T.E.D...Thanks a lot
maddy