Startup function

User avatar
Enrico Maria Giordano
Posts: 8728
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Startup function

Post by Enrico Maria Giordano »

Dear friends,

The MAIN() function is the startup function in Harbour and xHarbour. But in xHarbour the function MAIN() is the startup function only when its module is the first linked in. Do you know a way to specify a startup function in xHarbour that is not in the first linked module?
User avatar
Antonio Linares
Site Admin
Posts: 42256
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Startup function

Post by Antonio Linares »

Dear Enrico,

See this in source/vm/hvm.c
/* if first char is '@' then start procedure were set by
* programmer explicitly and should have the highest priority
* in other case it's the name of first public function in
* first linked moudule which is used if there is no
* HARBOUR_START_PROCEDURE in code
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 8728
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Startup function

Post by Enrico Maria Giordano »

Dear Antonio,

Can you explain, please? I don't understand how to set a specific startup function in xHarbour, if it is possible.
User avatar
Antonio Linares
Site Admin
Posts: 42256
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Startup function

Post by Antonio Linares »

Dear Enrico,

I am not sure about it, either. I am just showing you what I found. Look for HARBOUR_START_PROCEDURE

* source/pp/ppcore.c
+ Added predefined macro __HB_MAIN__. The macro is undefined or holds the
value of HARBOUR_START_PROCEDURE depending on the compiler.
Use this code to make your Harbour startup procedure platform/compiler
independent:
#ifndef __HB_MAIN__
#define __HB_MAIN__ AppMain /* Or whatever you wish to call it */
#endif
FUNCTION __HB_MAIN__()

2003-08-02 12:00 UTC+0200 Przemyslaw Czerpak <druzus@polbox.com>
* xharbour/make_tgz.sh
* xharbour/xharbour.spec
* xharbour/source/vm/hvm.c
* small modification in support for automatic detection of first
function in linked modules for Linux
if first char of s_pszLinkedMain is '@' then start procedure were
set by programmer explicitly and should have the highest priority
in other case it's then name of first public function in first
linked moudule which is used if there is no HARBOUR_START_PROCEDURE
in code
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42256
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Startup function

Post by Antonio Linares »

Me neither as function @Name() is not supported by the compiler...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
nageswaragunupudi
Posts: 10691
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Startup function

Post by nageswaragunupudi »

Sometimes I used @<funcname>() like this:

Code: Select all | Expand

    p  := ( @XBROWSE() )
   ? P
   HB_ExecFromArray(  p, { "STATES.DBF" } )

Code: Select all | Expand

p := ( @XBROWSE() )
works exactly like

Code: Select all | Expand

p := HB_FuncPtr( "XBROWSE" )
Regards

G. N. Rao.
Hyderabad, India
User avatar
Enrico Maria Giordano
Posts: 8728
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Startup function

Post by Enrico Maria Giordano »

Yes, it is the "address of" operator. But it has nothing to do with my request.
User avatar
karinha
Posts: 7884
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Contact:

Re: Startup function

Post by karinha »

Good morning Enrico. I don't quite understand what you want, wouldn't it be this:

https://www.hamor.ro/distr_ext/Doc/xHb/ ... re.en.html

??

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Enrico Maria Giordano
Posts: 8728
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Startup function

Post by Enrico Maria Giordano »

No. Look: Harbour uses MAIN() as the startup function even if it is not in the main PRG. xHarbour uses MAIN() only if it is in the main PRG. If it is not, xHarbour calls the first function defined in the main PRG. How to force xHarbour to call MAIN() even if it is not in the main PRG?
User avatar
karinha
Posts: 7884
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Contact:

Re: Startup function

Post by karinha »

I'm sorry. I've never seen anything like this. Why do you need this? What is the purpose?

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Enrico Maria Giordano
Posts: 8728
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Startup function

Post by Enrico Maria Giordano »

I just want that MAIN() is always executed at startup even if it is not in the main PRG, just like Harbour already does.
User avatar
karinha
Posts: 7884
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Contact:

Re: Startup function

Post by karinha »

Enrico, I learned it like this:

How to create an EXEcutable:

It is mandatory to have a FUNCTION MAIN() within your system, you already know this, but in xHarbour, even if you are compiling a single PRG, you will need to start with FUNCTION MAIN() too!

Enrico, lo aprendí así:
Cómo crear un ejecutable:

Es obligatorio tener una FUNCTION MAIN() dentro de su sistema, ya lo sabe, pero en xHarbour, incluso si está compilando un solo PRG, ¡también necesitará comenzar con FUNCTION MAIN()!

I've never seen any other way.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Enrico Maria Giordano
Posts: 8728
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Startup function

Post by Enrico Maria Giordano »

No, it is not mandatory to have a FUNCTION MAIN()! If you do not define it, the first function defined in the first linked PRG is executed at startup. But if you define it then the Harbour and xHarbour behaviour is different: Harbour executes it even if it is not in the first linked PRG while xHarbour execute it only if it is defined in the first linked PRG, otherwise it executes the first function defined in the first linked PRG, ignoring the MAIN() defined in another PRG. I don't know how to explain it better, sorry.
User avatar
karinha
Posts: 7884
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Contact:

Re: Startup function

Post by karinha »

If I understand you correctly... Is that +-?

Code: Select all | Expand

// C:\FWH\SAMPLES FUNCMAIN.PRG

#include "FiveWin.ch"

STATIC oWnd

FUNCTION Principal() // INIT PROCEDURE Principal // Main

  ? "I am the Principal() function"

  Main()

RETURN NIL

FUNCTION Main()

  ? "I am the Main() function"

RETURN NIL

// FIN / END
 
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Post Reply