GLOBAL e GLOBAL EXTERNAL

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

Avatar do usuário
asimoes
Colaborador
Colaborador
Mensagens: 4919
Registrado em: 26 Abr 2007 16:48
Localização: RIO DE JANEIRO-RJ

GLOBAL e GLOBAL EXTERNAL

Mensagem por asimoes »

Pesquisando,

Achei este tipo no documento do xHarbour, isso existe no harbour?

GLOBAL <varName> [:= <xValue> ]
GLOBAL EXTERNAL <extVarName>

GLOBAL <varName>
<varName> is the symbolic name of the global variable to declare.
<xValue>
<xValue> is an optional value to assign to the GLOBAL variable after being declared. To assign a value, the inline assignment operator (:=) must be used. The simple assignment operator (=) cannot be used. Only literal values are allowed for <xValue> when declaring GLOBAL variables.
GLOBAL EXTERNAL <extVarName>
This is the name of a GLOBAL variable that is declared in another PRG file and must be referred to in the current PRG file.
►Harbour 3.x | Minigui xx-x | HwGui◄
Pense nas possibilidades abstraia as dificuldades.
Não corrigir nossas falhas é o mesmo que cometer novos erros.
A imaginação é mais importante que o conhecimento. (Albert Einstein)
Avatar do usuário
Vlademiro
Usuário Nível 4
Usuário Nível 4
Mensagens: 752
Registrado em: 11 Jul 2005 02:46

GLOBAL e GLOBAL EXTERNAL

Mensagem por Vlademiro »

Eu testei aqui e não funcionou com Harbour 3.2

Testei dessa forma e ele nem compilou.

global.prg

Código: Selecionar todos

GLOBAL v := "Teste"

PROCEDURE Main
//GLOBAL v := "Teste"

   ? V
   ? PrcExterna()

RETURN
prc.prg

Código: Selecionar todos

GLOBAL EXTERNAL v
PROCEDURE PrcExterna()

   ? v

RETURN
Avatar do usuário
asimoes
Colaborador
Colaborador
Mensagens: 4919
Registrado em: 26 Abr 2007 16:48
Localização: RIO DE JANEIRO-RJ

GLOBAL e GLOBAL EXTERNAL

Mensagem por asimoes »

Acho que isso é exclusivo do xharbour
►Harbour 3.x | Minigui xx-x | HwGui◄
Pense nas possibilidades abstraia as dificuldades.
Não corrigir nossas falhas é o mesmo que cometer novos erros.
A imaginação é mais importante que o conhecimento. (Albert Einstein)
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

GLOBAL e GLOBAL EXTERNAL

Mensagem por JoséQuintas »

Também cheguei a testar se isso funcionava.
Já teria algum uso pra isso?
Resolvi com funções.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
asimoes
Colaborador
Colaborador
Mensagens: 4919
Registrado em: 26 Abr 2007 16:48
Localização: RIO DE JANEIRO-RJ

GLOBAL e GLOBAL EXTERNAL

Mensagem por asimoes »

Achei essa informação:


GLOBAL variables:

GLOBAL <Id1> [,<Id2> [,<IdN>]]

GLOBAL Variables are a new kind of a declared variables. they have PUBLIC like visibility, but are faster than even STATICs. GLOBALS can be referenced from other modules using the syntax:
GLOBAL EXTERNAL <Id1> [,<Id2> [,<IdN>]]

GLOBAL Variables have the added benefit of being *directly* accessible from C code too.

Sample code:

Código: Selecionar todos


//-------------------------------------//
GLOBAL g_MyObject
#include "hbclass.ch"
PROCEDURE Main()
   g_MyObject := MyClass()
   MyCFunction()
RETURN

CLASS MyClass
   METHOD MyMethod INLINE Alert( "MyMethod" )
ENDCLASS

#pragma BEGINDUMP
HB_FUNC( MYCFUNCTION )
{
   hb_objSendMsg( &G_MYOBJECT, "MyMethod", 0 );
   // Note must be ALL-CAPS!
}
#pragma ENDDUMP
//-------------------------------------//
►Harbour 3.x | Minigui xx-x | HwGui◄
Pense nas possibilidades abstraia as dificuldades.
Não corrigir nossas falhas é o mesmo que cometer novos erros.
A imaginação é mais importante que o conhecimento. (Albert Einstein)
Avatar do usuário
asimoes
Colaborador
Colaborador
Mensagens: 4919
Registrado em: 26 Abr 2007 16:48
Localização: RIO DE JANEIRO-RJ

GLOBAL e GLOBAL EXTERNAL

Mensagem por asimoes »

Bom, as minha duvidas foram esclarecidas:

### GLOBAL / GLOBAL EXTERNAL (GLOBAL_EXTERN) ###
======================================================
xHarbour support application wide static variables called GLOBALs.
To declare GLOBAL variable you have to put
GLOBAL <varname> [ := <initValue> ]
before the 1-st function in compiled .prg module and use -n compiler
switch. In xHarbour GLOBAL variables cannot be declared inside function
body. If user wants to use GLOBAL variable in different .prg module
then he has to add declaration
GLOBAL EXTERNAL <varname>
to his code before the 1-st function in compiled .prg module and use
-n compiler switch. Also, GLOBAL EXTERNAL declaration cannot be used
in function body. Unlike other variables GLOBALs declared in xHarbour
reserve used names so they cannot be used in the same module in local
function declarations, f.e. xHarbour cannot compile code like:
GLOBAL var
GLOBAL EXTERNAL var2
func F1( var )
return var * 2
func F2()
FIELD var2
return var2
due to name conflicts. In general users should be careful using the same
names for different type of variables in xHarbour.
GLOBAL variables in xHarbour need static link time bindings so they
do not work with dynamically loaded PCODE functions from .hrb files
or shared libraries (.dll, .so, .sl, .dyn, ...). Just like STATICs
they cannot be accessed by macro compiler.
Harbour does not support GLOBALs.
Fonte:https://github.com/vszakats/harbour-cor ... b-diff.txt
►Harbour 3.x | Minigui xx-x | HwGui◄
Pense nas possibilidades abstraia as dificuldades.
Não corrigir nossas falhas é o mesmo que cometer novos erros.
A imaginação é mais importante que o conhecimento. (Albert Einstein)
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

GLOBAL e GLOBAL EXTERNAL

Mensagem por JoséQuintas »

Na época entendi que seria igual variável pública, mas que poderia ser usada em multithread.
Exatamente esse foi meu interesse.

Mas já falamos disso em outro tópico.
Eu usei funções.

Código: Selecionar todos

FUNCTION AppVersao( xValue )
   STATIC x
   IF xValue != NIL
      x := xValue
   ENDIF
   RETURN x
Não precisa declarar variável, e o compilador avisa se o nome estiver errado.
Acaba sendo mais seguro.

Até pensei em declarar como classe, mas aí o compilador não vai avisar se errar o nome.
Ainda mais que meu computador está pedindo um teclado novo há bastante tempo, e de vez em quando as teclas falham e o teclado precisa de uma chacoalhada..... rs
Se não fosse a compilação -w3 -es2...... rs
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Responder