<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">OK, to partially answer my own question:<div><br></div><div>GNU getopt, which is used on Linux, changes the order of argv as a side effect: </div><div><br></div><div><a href="http://man7.org/linux/man-pages/man3/getopt.3.html">http://man7.org/linux/man-pages/man3/getopt.3.html</a></div><div><br></div><div>"By default, getopt() permutes the contents of argv as it scans, so that eventually all the nonoptions are at the end."</div><div><br></div><div>OS X uses a BSD getopt which is sane.</div><div><br></div><div>As Wikipedia says ( <a href="https://en.wikipedia.org/wiki/Getopt">https://en.wikipedia.org/wiki/Getopt</a> ) :</div><div><br></div><div>"getopt is a system dependent function. The implementation of getopt in GNU C Library does permute the contents of the argument vector as it scans, so that eventually all the non-option arguments are at the end. On the contrary, the implementation of getopt in BSD C Library does not permute the argument vector and returns -1 if it encounters a non-option argument."</div><div><br></div><div>The Self VM uses getopt to parse the VM options, then passes the arguments onto the Self world via argv. So on OSX it is normal argv, on Linux it is argv as altered by getopt:</div><div><br></div><div>In shell.cpp:</div><div><br></div><div><div>  OS::opterr= 0; // disable printed warning about unrecognized options</div><div>  while(opt_i= OS::optind,</div><div>        (c = OS::getopt(argc, (char* const*)argv, "Ff:hl:prtcs:woa")) != (char)-1) {</div><div>    if (strlen(argv[opt_i]) != 2) continue; // ignore multi-character options</div><div>    switch(c) {</div><div>    case 'F':</div></div><div><span class="Apple-tab-span" style="white-space:pre">   </span>etc ...</div><div><br></div><div><div>  // save remaining args for Self-level access</div><div>  prog_argc= argc;</div><div>  prog_argv= argv;</div></div><div><br></div><div>So my next question is, what is the best way to fix this so that _CommandLine returns the arguments in proper order on Linux?</div><div><br></div><div>Russell</div><div><br><div><div>On 1 Feb 2014, at 9:55 pm, Russell Allen <<a href="mailto:mail@russell-allen.com">mail@russell-allen.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><div id="ygrp-mlmsg" style="font-size: 13px; font-family: Arial, helvetica, clean, sans-serif; position: relative;"><div id="ygrp-msg" style="line-height: 1.22em; z-index: 1;"><div id="ygrp-text" style="line-height: 1.22em; font-family: Georgia;"><p style="line-height: 1.22em; margin: 0px 0px 1em;">Just in case anyone has any ideas, I get this in OS X as expected:</p><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;"><div style="line-height: 1.22em;">Macintosh-2:mio russellallen$<span class="Apple-converted-space"> </span><font color="#008f00" style="line-height: 1.22em;">Self -port 4000 -headless</font></div><div style="line-height: 1.22em;">Self Virtual Machine Version 4.1.13, Thu 09 Jan 14 15:06:29 Mac OS X i386 (4.4-272-g885323f-dirty)</div><div style="line-height: 1.22em;">Copyright 1989-2003: The Self Group (type _Credits for credits)</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">for I386:  LogVMMessages = true</div><div style="line-height: 1.22em;">for I386:  PrintScriptName  = true</div><div style="line-height: 1.22em;">for I386:  Inline = true</div><div style="line-height: 1.22em;">for I386:  SICDeferUncommonBranches = false (not implemented)</div><div style="line-height: 1.22em;">for I386:  SICReplaceOnStack = false (not implemented)</div><div style="line-height: 1.22em;">for I386:  SaveOutgoingArgumentsOfPatchedFrames = true</div><div style="line-height: 1.22em;">VM# _CommandLine</div><div style="line-height: 1.22em;"><font color="#008f00" style="line-height: 1.22em;"><0>: ( | parent* = <1>. | object array: {'/Applications/Self Control.app/Contents/Resources/Self.app/Contents/MacOS/Self', '-port', '4000', '-headless'} )</font></div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div></div><div style="line-height: 1.22em;">but I get this in Linux (Fedora 19):</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;"><div style="line-height: 1.22em;">[self@messaging ~]$<font color="#008f00" style="line-height: 1.22em;"><span class="Apple-converted-space"> </span>./selfvm -port 4000 -headless</font></div><div style="line-height: 1.22em;">Self Virtual Machine Version 4.1.13, Sat 01 Feb 14 08:00:32 Linux i386 (4.5.0-7-gb833000)</div><div style="line-height: 1.22em;">Copyright 1989-2003: The Self Group (type _Credits for credits)</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">for I386:  LogVMMessages = true</div><div style="line-height: 1.22em;">for I386:  PrintScriptName  = true</div><div style="line-height: 1.22em;">for I386:  Inline = true</div><div style="line-height: 1.22em;">for I386:  SICDeferUncommonBranches = false (not implemented)</div><div style="line-height: 1.22em;">for I386:  SICReplaceOnStack = false (not implemented)</div><div style="line-height: 1.22em;">for I386:  SaveOutgoingArgumentsOfPatchedFrames = true</div><div style="line-height: 1.22em;">VM# _CommandLine</div><div style="line-height: 1.22em;"><font color="#008f00" style="line-height: 1.22em;"><0>: ( | parent* = <1>. | object array: {'./selfvm', '-port', '-headless', '4000'} )</font></div></div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">Why on earth would the order of the command line arguments vary between platforms? Or more precisely, why is Linux reordering my arguments?</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;">Russell</div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em;"><br style="line-height: 1.22em;"></div><div style="line-height: 1.22em; margin: 0px 0px 1em;"><br class="webkit-block-placeholder"></div></div><div style="line-height: 1.22em; color: rgb(255, 255, 255); height: 0px;"></div></div></blockquote></div><br></div></body></html>