TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Byron Desnoyers
from: Jonathan de Boyne Pollard
date: 1995-04-19 09:37:24
subject: Having An Argument

ZZ>
  > int main ( int argc, char *argv[] )
  >  {
  >  // program code
  >  }
  >
  > However, when I run the program for DOS, by typing "PORTDOS" it will
  > return the command line as "G:\PROGRAM\PORTDOS.EXE".  Yet the OS/2
  > program (run by typing "PORTOS2") will return it as
"PORTOS2"
ZZ>

  If you mean the contents of argv[0], then the OS/2 C++ compiler is
  closer to the original (UNIX) semantics than the DOS C++ compiler.

  The original semantics of argv[0] were that it should contain whatever
  name was used to invoke the program *before* resolving the name by
  searching along the PATH.

  Unfortunately, the DOS command interpreter never supplied this
  information.  About the only thing that you are given by COMMAND.COM
  is the fully-qualified name of the program, so that is all that DOS
  C++ implementations have available to use for argv[0].

  On the other hand, the OS/2 command interpreter supplies both the
  fully qualified name of the executable *and* the name that was
  actually typed at the command line, so argv[0] is constructed with the
  "proper" value in most (but, ironically, not all) OS/2 C++
  implementations.

  To obtain the fully-qualified path name of an executable, use the
  source snippet that Peter Fitzsimmons posted here a week ago (it used
  DosGetInfoBlocks and DosQueryModuleName).

  Moral : Don't rely on argv[0] having the same semantics across
          platforms.  Platforms like DOS have limitations that break
          the customary semantics.

  > JdeBP <
___
 X MegaMail 2.10 #0: Oklahoma? Pah! A bomb exploded in Belfast EVERY WEEK.
--- Maximus/2 2.02
* Origin: DoNoR/2,Woking UK (44-1483-722344) (2:440/4)
SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 440/4 141/209 270/101 105/103 42 712/515 711/808 809 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™.