FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Qu茅 es lo err贸neo?
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Qu茅 es lo err贸neo?
Posted: Tue Jan 15, 2019 05:18 PM
Amigos:
Alguno de ustedes puede decirme, 驴que es lo malo en el siguiente codigo?

Code (fw): Select all Collapse
#DEFINE USAR_PRINTLIB  IF( Type("VerImpMetaF()") == "U", 0, 1 )

Function Main()

MSGINFO( USAR_PRINTLIB )

#if USAR_PRINTLIB == 0        //Aqui salta el error en tiempo de compilacion Error E0025  Error in #if expression
   #undef USAR_PRINTLIB
   MsgInfo("NO ESTA LINKEADA")
#endif

Return nil
Francisco J. Alegr铆a P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: Qu茅 es lo err贸neo?
Posted: Tue Jan 15, 2019 05:23 PM
Tambien lo hice asi, y el mismo resultado.

Syntax
#if <condition1>
<statements1>
[ #elif <conditionN>
<statmentsN> ]
[ #else
<statments> ]
#endif

Arguments
<condition1> .. <conditionN>
<condition> is one or more logical conditions that are resolved by the preprocessor. Conditions are formulated using #define constants, numeric or logical literal values. A condition expression may include comparison operators.
<statements1> .. <statementsN>
<statements> is the program code to include in the preprocessor output when a condition is true. Description

Code (fw): Select all Collapse
#DEFINE USAR_PRINTLIB 聽IF( Type("VerImpMetaF()") == "U", 0, 1 )
#DEFINE NO_USARLA 聽 聽 聽0

Function Main()

#if USAR_PRINTLIB == NO_USARLA 聽 聽 聽 聽//Aqui salta el error en tiempo de compilacion Error E0025 聽Error in #if expression
聽 聽#undef USAR_PRINTLIB
聽 聽MsgInfo("NO ESTA LINKEADA")
#endif

Return nil
Francisco J. Alegr铆a P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Qu茅 es lo err贸neo?
Posted: Tue Jan 15, 2019 05:34 PM
  1. Tal como le indic贸 aqu铆 (viewtopic.php?f=6&t=36600#p218321) el master Antonio, hay que preguntar por UI y no simplemente por U.

  2. Como directiva de compilacion el #if A == B es err贸neo.

Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: Qu茅 es lo err贸neo?
Posted: Tue Jan 15, 2019 05:59 PM
hmpaquito wrote:1. Tal como le indic贸 aqu铆 (http://forums.fivetechsupport.com/viewt ... 00#p218321) el master Antonio, hay que preguntar por UI y no simplemente por U.

2. Como directiva de compilacion el #if A == B es err贸neo.



1 - Cuando uso Type("VerImpMetaF()"), el resultado es "U".
"U" NIL, local or static variable, or not linked-in function
"UE" syntax error in the expression or invalid arguments
"UI" function with non-reserved name was requested

2 - tomado del manuel de xHarbour
The #if..#elif..#else..#endif directives are used for conditional compilation. They work analogous to the IF..ELSEIF..ELSE..ENDIF statements, but are resolved by the preprocessor, rather than the compiler. In contrast to the #ifdef and #ifndef directives, which test only the presence or absence of #define constants, #if allows for testing the values of such constants and comparing them with other values. In addition, multiple conditions can be formulated using #if..#elif. When the #else directive is used, it must be the last one, followed by #endif.
The statements following the first condition that resolves to True is included in the preprocessor output. All other statements are discarded. That means, even if multiple conditions are True, only one of the code statements appears in the preprocessor output. When all conditions are False, the statements following the #else directive, if present, are used.
The following rules are applied by the preprocessor to evaluate a condition:

1. A numeric literal <> 0 yields True, while exact zero yields False.
2. The logical literal .T. is True, .F. is False.
3. #define constants with no associated value yield False.
4. The literal value NIL yields False.
5. Other literal values cannot be used and result in a compile error.
6. Numeric values can be compared using the comparison operators !=, #, >, >=, =, ==, =< and <. The True/False result of the comparison is evaluated by the preprocessor.

// The example demonstrates how the same source code file can be
// compiled for different program versions. Depending on the #define
// constant MAKE_VERSION, differen initilization routines are called.

#define FULL_VERSION 3
#define RESTRICTED_VERSION 2
#define DEMO_VERSION 1

#define MAKE_VERSION RESTRICTED_VERSION

PROCEDURE Main
#if MAKE_VERSION > RESTRICTED_VERSION
InitFullPackage()
#elif MAKE_VERSION > DEMO_VERSION
InitRestrictedPackage()
#else
InitDemoPackage()
#endif

Code (fw): Select all Collapse
#DEFINE USAR_PRINTLIB 聽IF( Type("VerImpMetaF()") == "U", 0, 1 )
#DEFINE NO_USARLA 聽 聽 聽0

Function Main()

#if USAR_PRINTLIB > NO_USARLA 聽 聽 聽 聽//Aqui salta el error en tiempo de compilacion Error E0025 聽Error in #if expression
聽 聽MsgInfo("ESTA LINKEADA")
#elif USAR_PRINTLIB == NO_USARLA 聽 聽 聽 聽//Aqui salta el error en tiempo de compilacion Error E0025 聽Error in #if expression
聽 聽#undef USAR_PRINTLIB
聽 聽MsgInfo("NO ESTA LINKEADA")
#endif

Return nil
Francisco J. Alegr铆a P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Qu茅 es lo err贸neo?
Posted: Tue Jan 15, 2019 06:04 PM
  1. ok entendido, mi error.

  2. Lo que no se pueden usar son expresiones que deben ser procesadas en tiempo de ejecucion.
    No es lo mismo #if 1 > 0 que #if Len("paco") > len("Francisco"). La primera se puede resolver en tiempo de compilacion, que es el "tiempo" de las directivas del compilador. La segunda no.

Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: Qu茅 es lo err贸neo?
Posted: Tue Jan 15, 2019 06:14 PM

Gracias hmpaquito, por tu inter茅s.
A煤n contin煤a el error.

Francisco J. Alegr铆a P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 147
Joined: Tue Oct 11, 2005 08:22 PM
Re: Qu茅 es lo err贸neo?
Posted: Tue Jan 15, 2019 06:38 PM

Hola

Creo que el problema puede venir en que los DEFINES se resuelven en tiempo de compilaci贸n y el llamado a la funci贸n Type se resuelve en ejecuci贸n, a los defines debes ponerles valores constantes, tu ejemplo compila correctamente de la siguiente manera:

// #DEFINE USAR_PRINTLIB IF( Type("VerImpMetaF()") == "U", 0, 1 )

Function Main()
LOCAL USAR_PRINTLIB := IF( Type("VerImpMetaF()") == "U", 0, 1 )

MSGINFO( USAR_PRINTLIB )

if USAR_PRINTLIB == 0 //Aqui salta el error en tiempo de compilacion Error E0025 Error in #if expression
// #undef USAR_PRINTLIB
MsgInfo("NO ESTA LINKEADA")
endif

Return nil

Saludos

Eduardo Borondon Mu帽iz

Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: Qu茅 es lo err贸neo?
Posted: Tue Jan 15, 2019 08:13 PM
Eduardo.
Gracias por contestar.
Estoy de acuerdo que asi compila sin problemas, pero no es lo que busco.

Lo que quiero hacer es, en base al valor asignado a DEFINE USAR_PRINTLIB mediante la funcion Type(NombreFunctEnLib), (que lo toma correctamente),
es usar ese valor (cuando es 0) para #UNDEF USAR_PRINTLIB.

Posteriormente usariamos en el menu:
MENUITEM "Opciones"
MENU
MENUITEM "UNO" ACTION XXX
#IFDEF USAR_PRINTLIB
MENUITEM "Hola" ACTION NombreFunctEnLib()
#ENDIF
...

Es decir, condicionar el MENUITEM conforme a si fu茅, o no, linkeada la libreria que contiene la function NombreFunctEnLib) descrita.

Saludos.
Francisco J. Alegr铆a P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Qu茅 es lo err贸neo?
Posted: Wed Jan 16, 2019 08:28 AM
FranciscoA wrote:Lo que quiero hacer es, en base al valor asignado a DEFINE USAR_PRINTLIB mediante la funcion Type(NombreFunctEnLib), (que lo toma correctamente),
es usar ese valor (cuando es 0) para #UNDEF USAR_PRINTLIB.


No lo veo posible por dos motivos:

Primero, como coment茅 la evaluacion de Type() se realiza en tiempo de ejecuci贸n y
Segundo, Harbour compila m贸dulo (.prg) a m贸dulo, y s贸lo al final, en el linkado, conoce si una funci贸n fue enlazada o no.

Hay que montar el sistema de otra forma. Por ejemplo, al compilar detectar si existe un determinado archivo y si existe se pasa una define (-D)
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: Qu茅 es lo err贸neo?
Posted: Wed Jan 16, 2019 07:32 PM
Code (fw): Select all Collapse
Function Main()
聽 聽 LOCAL USAR_PRINTLIB := IF( Type(VerImpMetaF()) == "U", 0, 1 )

聽 聽 if USAR_PRINTLIB == 0 
聽 聽 聽 聽 MsgInfo("NO ESTA LINKEADA")
聽 聽 endif

Return nil
______________________________________________________________________________

Sevilla - Andaluc铆a

Continue the discussion