[Gambas-devel] don't understand...WHO I'm wrong ??

Benoit Minisini gambas at ...1...
Sat Jul 17 01:11:20 CEST 2004


On Friday 16 July 2004 02:26, Charlie Reinl wrote:
> Salut,
>
> from  file:/opt/gambas/share/gambas/help/ApiVARGOPT.html
> ---------------------------------------------------------------------------
>------------------------------------------------------ VARGOPT
>
>
> #define VARGOPT ( name , default ) (MISSING( name ) ? ( default ) :
> VARG( name ))
>
>
> Returns the value of an argument from its name, or a default value if this
> argument is missing.
>
> name is the name of the argument.
> default is the default value.
>
> This is a useful combination of the macros MISSING and VARG.
> ---------------------------------------------------------------------------
>------------------------------------------------------ I mean :
> ?????????????????????????????
>
> but can someone explaine me what that mean !
>
> I dit:
> 	if (MISSING(bUseTab))
> 		VARGOPT(bUseTab,FALSE);
> 		//VARG(bUseTab) = FALSE;
> 	if (MISSING(iSpace))
> 		//VARG(iSpace) = (WIDGET->tabSpace());
> 		VARGOPT(iSpace,(WIDGET->tabSpace()));
> 	if (MISSING(bEvery))
> 		//VARG(bEvery) = TRUE;
> 		VARGOPT(bEvery,TRUE);
> 	if (MISSING(bEveryWithOutDim))
> 		//VARG(bEveryWithOutDim) = TRUE;
> 		VARGOPT(bEveryWithOutDim,TRUE);
> 	if (MISSING(bAlignComments))
> 		//VARG(bAlignComments) = TRUE;
> 		VARGOPT(bAlignComments,TRUE);
> 	if (MISSING(bWithInCase))
> 		//VARG(bWithInCase) = TRUE;
> 		VARGOPT(bWithInCase,TRUE);
> 	if (MISSING(bDelEmptyLines))
> 		//VARG(bDelEmptyLines) = TRUE;
> 		VARGOPT(bDelEmptyLines,TRUE);
>
> 	if (!VARG(bEvery))
> 	{
> 		//VARG(bEveryWithOutDim) = FALSE;
> 		VARGOPT(bEveryWithOutDim,FALSE);
>  		//VARG(bAlignComments) = FALSE;
> 		VARGOPT(bAlignComments,FALSE);
>  	}
>
> I'v got :
>
> /bin/sh ../../../../libtool --mode=compile g++ -DHAVE_CONFIG_H -I. -I.
> -I../../../.. -I../../../../src/share  -I/usr/qt/3/include/ -D_REENTRANT
> -g -O2 -pipe -Wall -fno-exceptions -g -Os -c CEditor.cpp
> g++ -DHAVE_CONFIG_H -I. -I. -I../../../.. -I../../../../src/share
> -I/usr/qt/3/include/ -D_REENTRANT -g -O2 -pipe -Wall -fno-exceptions -g -Os
> -c CEditor.cpp  -fPIC -DPIC -o CEditor.lo
> CEditor.cpp: In function `void CEDITOR_PrettyPrinter(void*, void*)':
> CEditor.cpp:557: warning: statement with no effect
> CEditor.cpp:564: warning: statement with no effect
> CEditor.cpp:567: warning: statement with no effect
> CEditor.cpp:570: warning: statement with no effect
> CEditor.cpp:573: warning: statement with no effect
> CEditor.cpp:576: warning: statement with no effect
> CEditor.cpp:581: warning: statement with no effect
> CEditor.cpp:583: warning: statement with no effect
>
> AND I'v heart that :
> 	..... because you are modifying the interpreter stack, and this could be
> dangerous!
>
> WHO I'm wrong ??
>
> Amicalement
> Charlie
>
>

Maybe I was not very clear.

You must use VARG() to return a value from the stack, not to set it.

If you have an optional argument, read it with VARGOPT(), the second parameter 
being the optional value.

In other words, you have three ways to get an optional argument:

1) Use VARGOPT() each time you read it.

  CallMyPrettyPrinter(VARG(bUseTab, FALSE), VARG(iTabSpace, 
WIDGET->tabSpace()), ...)

2) Or use a temporary local variable, if you must read the same parameter many 
times.

  bool useTab = VARGOPT(bUseTab, FALSE);
  int tabSpace = VARGOPT(iTabSpace, WIDGET->tabSpace());
  ...

  CallMyPrettyPrinter(useTab, tabSpace, ...);

3) Use MISSING() directly, which is finally equivalent.

I suggest you find a good book that explain you how works the C preprocessor. 
If you really have problems with it, you can use the '-E' option of gcc, that 
allows you to see the code generated by the preprocessor just before it is 
compiled.

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the Devel mailing list