TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Francois Thunus
from: Jonathan de Boyne Pollard
date: 1996-10-10 01:33:36
subject: silly findfirst question

FT>
  > #include 
  >
  > int main(int argc, char **argv)
  > {
  >    char         *Search;
  >    FILEFINDBUF3 *FindBuf;
  >
  >    FindBuf=malloc(sizeof(FILEFINDBUF3));
  >    strcpy(Search,argv[1]);
  >
  >    return(0);
  > }
  >
  > 1) I'm getting a warning
  > "assignment makes pointer from integer without a cast" on
the malloc line
  > why ? I've always done that under dos and my compiler never complained ?
FT>

  But, nevertheless, your code has always been duff.

  It's just that up until now, you've been using a duff compiler to
  compile it.

  In the C language, unless you #include , malloc implicitly
  returns an integer.  This is being cast to a pointer in the assignment
  expression, which is a non-portable construct, hence the compiler
  warning.

  If you were using the C++ language, then your failure to declare the
  malloc function before using it would be an error, and your program
  would not compile.

FT>
  > 2) when compiled to dual standart (ie dos/os/2 exe with rsx/emx.dll) it
  > still works under os/2 but bombs out with GP in a dos box.
FT>

  You are very lucky.  As you can see, your `Search' variable doesn't
  point to anything (and can actually have any random value, since it is a
  variable with automatic storage which you haven't initialised).

  Always declare your functions, and always initialise your automatic
  variables.

  > JdeBP <
___
 X MegaMail 2.10 #0:
--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-725167) (2:440/4)
SEEN-BY: 50/99 270/101 620/243 625/100 711/401 409 410 413 430 808 809 934
SEEN-BY: 711/955 712/407 515 624 628 713/888 800/1
@PATH: 440/4 141/209 270/101 712/515 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.