[comp.unix.wizards] system 5 vrs. bsd4.3 question

decot@hpisod2.HP.COM (Dave Decot) (07/20/89)

Replace:

   main(argc, argv)
   int argc;
   char *argv[];

with

   main(argc, argv, envp)
   int argc;
   char *argv[], *envp[];

and your troubles should go away.  It is likely that the exec(2) page
in your SGI documentation has the explanation of envp.

Sounds like SGI has an unusual argument passing method.

Dave

dxk@beta.lanl.gov (David M Koon) (08/15/89)

I am trying to port the following code from a Sun( it also works 
on a PC with turbo C) to a Silicon Graphics(system V).

#include <stdio.h>
#include <string.h>
#include <time.h>
#include "cffs.h"
 
main(argc,argv)
int argc;
char *argv[];
{
....
However, on the SGI machine argc is undefined and argv seems to contain
the environmental variables.  Does anyone have any ideas as to what is 
causing this and how I can fix it?  I am compiling in the Sun with
cc fn.c -o fn
and on SGI with
cc fn.c -o fn.
Thanks,
Dave Koon
Los Alamos National Laboratory
dxk@lanl.gov

gavin@krypton.sgi.com (Gavin A. Bell) (09/06/89)

dxk@beta.lanl.gov (David M Koon) writes:

>I am trying to port the following code from a Sun( it also works 
>on a PC with turbo C) to a Silicon Graphics(system V).

>#include "cffs.h"
> 
>main(argc,argv)

There was a question exactly like this a couple of months ago.  Look
for a missing semicolon at the end of cffs.h

A missing semicolon probably make the code look like:

struct foo {...} main(argc,argv) { ... }

... that is, main is a 'struct foo'.  Most compilers don't care, but
the Mips compiler used on SGI machines seems to get quite confused.
This probably isn't unreasonable, since main() should always be
declared either   void   or   int.

This has nothing to do with SYSV versus BSD.

--gavin

rogerk@mips.COM (Roger B.A. Klorese) (09/06/89)

In article <454@odin.SGI.COM> gavin@krypton.sgi.com (Gavin A. Bell) writes:
>A missing semicolon probably make the code look like:
>struct foo {...} main(argc,argv) { ... }
>... that is, main is a 'struct foo'.  Most compilers don't care, but
>the Mips compiler used on SGI machines seems to get quite confused.

It doesn't get confused; it simply uses a different format for the
parameter list when functions return struct.  A dummy first entry is
added to hold the address of an instance of the appropriate struct
into which the return value is placed.  Unfortunately, the startup
code, which always calls "main" as an int function, expects argc to
be there.
-- 
ROGER B.A. KLORESE      MIPS Computer Systems, Inc.      phone: +1 408 720-2939
928 E. Arques Ave.  Sunnyvale, CA  94086                        rogerk@mips.COM
{ames,decwrl,pyramid}!mips!rogerk
"I want to live where it's always Saturday."  -- Guadalcanal Diary