proto-FAQ -- reactions please!_(re)

Fri, 18 Oct 1996 00:28:11 +0100 (MET)


According to Sven Hilscher:
> Would be a nice thing - but it dos'nt work ...
> If you call this GetEnv you get an error:
> "incompatible type for argument 1 of 'GetEnv'"

It does work with me, on Linux as well as with DJGPP.
EMX compiles it without complain but doesn't read the
environment variable :-( I have to investigate this ...)

> The other way :
>   function GetEnv(name : PChar): PChar; C;
> 
> This also not work with the string-conversion from the faq ;-(
> Every time I get a empty string from "GetEnv". (I tried it under DOS.)

Same as what I get with __CString__ and EMX.

> Moment please ... I think I've found a solution:
> 
>   Function GetEnv (var Name: __CString__ ): pChar; C;
>                    ^^^
> You get a warning about incompatible pointers, but it works ...
> Please remove this stupid warning and I'm happy. Yes, I know - I can use  
> {$W-}, but it's not so elegant ;-)

It's getting more and more strange ... this (with "var") should 
*not* work: __CString__ already denotes a pointer as required by
the C library function, and with "var" you pass a pointer to that
pointer ... no, the latter was wrong.  Your function *expects* a
pointer to the pointer, but you pass the pointer itself, so you
get the warning, but you pass the correct thing.  It works.  ;-)

However the correct thing would still be

    Function GetEnv ( Name: __CString__ ): pChar; C;

without "var".  You are using DJGPP, correct?  There it worked
on my computer.  Try the "GetEnv" from BO5s (no apostrophy: it's
a German abbreviation ;) "Tools" Unit.  (Must probably isolate it 
because BO5 is not (yet!) ready to work with DJGPP.)  It worked
here also.

    Peter

      e-mail:  peter.gerwinski@uni-essen.de
home address:  D\"usseldorfer Str. 35, 45145 Essen, Germany
         WWW:  http://agnes.dida.physik.uni-essen.de/~peter/


Peter Gerwinski (peter@agnes.dida.physik.uni-essen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es