This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Label question


On 19-Sep-2002, Mustafa Celik <celikmus@hotmail.com> wrote:
> 
> Can a label be defined globally?  All I want is to have an array of label 
> addresses, and a bunch of labels. I want to write the work that each label 
> does seperately.
> 
> You might be asking why labels? I don't want to use labels as they are 
> meant, but I don't know if there is anything else in GCC as close to what I 
> want. Labels simply provide an address which you can jump to anytime in 
> scope. I also want my code to jump some other places globally, to some code 
> I want be executed.
> 
> Is it possible at all?

Why do you want this?
And how important is efficiency?

The following paper [1] describes some techniques for achieving this
effect.  The simplest of these techniques is portable ANSI C, but is
not very efficient.  The fastest relies on behaviour of GNU C which
is not guaranteed by the GNU C documentation.  This technique is
used by the Mercury compiler.  (See the file runtime/mercury_goto.h
in the Mercury distribution; the code there has some additional
stuff not mentioned in our 1995 paper which is needed to make
this technique work on more recent versions of GCC.)

An alternative not mentioned in this paper (since it was not available
at the time) is to just rely on GCC's sibling call optimization.
Currently there are a lot of limitations with this.  But depending
on your exact requirements, it might be possible to make that
approach work.

References
[1] "Compiling logic programs to C using GNU C as a portable assembler."
    Fergus Henderson, Zoltan Somogyi and Thomas Conway. 
    Proceedings of the ILPS '95 Postconference Workshop on Sequential
    Implementation Technologies for Logic Programming Languages.
    Portland, Oregon, December 1995.  Available via
    <http://www.cs.mu.oz.au/mercury/information/papers.html#mercury_to_c>.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]