<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: strcmp different behaviour between HPUX and LINUX in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249242#M677724</link>
    <description>Hi&lt;BR /&gt;&lt;BR /&gt;from HPUX man pages I see that strcmp does conform to ANSI C standard:&lt;BR /&gt;&lt;BR /&gt;STANDARDS CONFORMANCE&lt;BR /&gt;strcmp(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C&lt;BR /&gt;&lt;BR /&gt;whereas from LINUX man pages I see:&lt;BR /&gt;&lt;BR /&gt;CONFORMING TO&lt;BR /&gt;       SVr4, 4.3BSD, C89, C99.&lt;BR /&gt;&lt;BR /&gt;Does it means that the linux implementation does not conform ANSI C?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Giuseppe&lt;BR /&gt;</description>
    <pubDate>Tue, 27 Jul 2010 16:45:06 GMT</pubDate>
    <dc:creator>Fedele Giuseppe</dc:creator>
    <dc:date>2010-07-27T16:45:06Z</dc:date>
    <item>
      <title>strcmp different behaviour between HPUX and LINUX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249239#M677721</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I have experienced that the following code works on HPUX but does not on LINUX.&lt;BR /&gt;&lt;BR /&gt;It seems that on LINUX the strcmp doesn't manage pointers to not allocated veriables.&lt;BR /&gt;&lt;BR /&gt;Which is the reason?&lt;BR /&gt;&lt;BR /&gt;  char **x;&lt;BR /&gt;&lt;BR /&gt;  if(strcmp(*x, "") == 0 )&lt;BR /&gt;  {&lt;BR /&gt;     printf("EQUAL\n");&lt;BR /&gt;  }else&lt;BR /&gt;  {&lt;BR /&gt;    printf("DIFFERENT\n");&lt;BR /&gt;  }</description>
      <pubDate>Tue, 27 Jul 2010 14:29:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249239#M677721</guid>
      <dc:creator>Fedele Giuseppe</dc:creator>
      <dc:date>2010-07-27T14:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: strcmp different behaviour between HPUX and LINUX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249240#M677722</link>
      <description>I see in strcmp HPUX man page that:&lt;BR /&gt;&lt;BR /&gt;"Null pointer values for s1 and s2 are treated the same as pointers to empty strings."&lt;BR /&gt;&lt;BR /&gt;and this should explain why it works on HPUX.&lt;BR /&gt;&lt;BR /&gt;Now my doubt is about linux behaviuor: is it a different implementation of the routine in this operating system?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Giuseppe</description>
      <pubDate>Tue, 27 Jul 2010 15:00:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249240#M677722</guid>
      <dc:creator>Fedele Giuseppe</dc:creator>
      <dc:date>2010-07-27T15:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: strcmp different behaviour between HPUX and LINUX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249241#M677723</link>
      <description>Yes it is a different implementation on Linux.  It does conform to the standards: SVr4, 4.3BSD, C89, C99.&lt;BR /&gt;&lt;BR /&gt;Did you remember to include string.h and allocate and initialize x?&lt;BR /&gt;&lt;BR /&gt;-Dave&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Jul 2010 16:30:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249241#M677723</guid>
      <dc:creator>David Johns</dc:creator>
      <dc:date>2010-07-27T16:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: strcmp different behaviour between HPUX and LINUX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249242#M677724</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;from HPUX man pages I see that strcmp does conform to ANSI C standard:&lt;BR /&gt;&lt;BR /&gt;STANDARDS CONFORMANCE&lt;BR /&gt;strcmp(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C&lt;BR /&gt;&lt;BR /&gt;whereas from LINUX man pages I see:&lt;BR /&gt;&lt;BR /&gt;CONFORMING TO&lt;BR /&gt;       SVr4, 4.3BSD, C89, C99.&lt;BR /&gt;&lt;BR /&gt;Does it means that the linux implementation does not conform ANSI C?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Giuseppe&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Jul 2010 16:45:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249242#M677724</guid>
      <dc:creator>Fedele Giuseppe</dc:creator>
      <dc:date>2010-07-27T16:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: strcmp different behaviour between HPUX and LINUX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249243#M677725</link>
      <description>Hi Fedele:&lt;BR /&gt;&lt;BR /&gt;C89 and C99 are the 1989 and 1999 ANSI C standards.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; It seems that on LINUX the strcmp doesn't manage pointers to not allocated veriables.&lt;BR /&gt;&lt;BR /&gt;Please see the following:&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;STRING.H&gt;&lt;BR /&gt;&lt;BR /&gt;int&lt;BR /&gt;main(int argc, char *argv[])&lt;BR /&gt;{&lt;BR /&gt;        char    **x;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;        printf("%p\n", (void *) x);&lt;BR /&gt;        printf("%p\n", (void *) *x);&lt;BR /&gt;        printf("%d\n",  **x);&lt;BR /&gt;        return EXIT_SUCCESS;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;%./a.out&lt;BR /&gt;0x773600&lt;BR /&gt;0x57e58955&lt;BR /&gt;Segmentation fault&lt;BR /&gt;&lt;/STRING.H&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Tue, 27 Jul 2010 17:41:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249243#M677725</guid>
      <dc:creator>David Johns</dc:creator>
      <dc:date>2010-07-27T17:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: strcmp different behaviour between HPUX and LINUX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249244#M677726</link>
      <description>&lt;!--!*#--&gt;You're dereferencing an uninitialized pointer. The C programming language does not guarantee that this will work.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; is it a different implementation of the routine in this operating system?&lt;BR /&gt;&lt;BR /&gt;Yes, the implementation is different.&lt;BR /&gt;HP-UX contains HP's own C library, while Linux uses open-source GNU glibc.&lt;BR /&gt;&lt;BR /&gt;By ANSI C, the strcmp(3) function is not required to accept NULL parameters. This may be a feature of some standards that HP-UX complies with but Linux does not. Or it might be a HP-UX specific feature.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You're also making three dangerous assumptions:&lt;BR /&gt;&lt;BR /&gt;1.) that the uninitialized memory location assigned to store **x contains by default a bit pattern that is equivalent to a NULL pointer. &lt;BR /&gt;&lt;BR /&gt;This depends on the hardware architecture and OS implementation, and is not generally guaranteed.&lt;BR /&gt;&lt;BR /&gt;2.) that you can dereference a NULL pointer, i.e. you can read *(NULL).&lt;BR /&gt;&lt;BR /&gt;Whenever possible, Linux guarantees that this *is not* true.&lt;BR /&gt;&lt;BR /&gt;I understand that in modern Linux, the NULL address is usually "booby-trapped", so that any attempt to dereference it is guaranteed to cause the program to crash immediately with a segmentation fault. As a result, the platform will force you to break bad habits and to write portable code.&lt;BR /&gt;&lt;BR /&gt;3.) that there is a NULL value at the end of the NULL pointer:&lt;BR /&gt; &lt;BR /&gt;( (void *) *(NULL) ) == NULL&lt;BR /&gt;&lt;BR /&gt;The original ANSI C standard does not define this; the result of dereferencing a NULL pointer will be platform-specific undefined behaviour. Any program that assumes it can successfully dereference a NULL pointer will not be _portable_ ANSI C.&lt;BR /&gt;&lt;BR /&gt;In program code:&lt;BR /&gt;&lt;BR /&gt;char **x;&lt;BR /&gt;&lt;BR /&gt;x = NULL;&lt;BR /&gt;&lt;BR /&gt;printf("If this program crashes now, assumption 2 is incorrect because *x is not accessible\n");&lt;BR /&gt;if ( *x == NULL ) {&lt;BR /&gt;   printf("Assumptions 2 and 3 are correct, at least this time.\n");&lt;BR /&gt;} else {&lt;BR /&gt;   printf("Assumption 2 is correct but assumption 3 is incorrect: *x is accessible but is not NULL\n");&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;By what I understand, these assumptions used to be valid in HP-UX (older PA-RISC versions at least). This allows some pointer algorithms to be written in more compact form, with less explicit tests for NULL.&lt;BR /&gt;&lt;BR /&gt;But later this has been found to encourage sloppy thinking and sloppy coding. It also causes pain when code must be ported from an architecture that allows dereferencing NULL to an architecture that doesn't.&lt;BR /&gt;&lt;BR /&gt;(For example, in the old Commodore 64, the memory addresses 0x0000 and 0x0001 contained important hardware control registers. Because there was no MMU and no way to create a virtual address space for user-space process, setting *(NULL) to NULL would have, among other things, disabled all system ROMs and started the cassette tape drive motor.)&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Tue, 27 Jul 2010 21:13:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249244#M677726</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2010-07-27T21:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: strcmp different behaviour between HPUX and LINUX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249245#M677727</link>
      <description>On my Linux/x86_64, the result of David's program is:&lt;BR /&gt;&lt;BR /&gt;$ ./a.out&lt;BR /&gt;(nil)&lt;BR /&gt;Segmentation fault&lt;BR /&gt;&lt;BR /&gt;In other words, Linux can be more strict than HP-UX used to be.&lt;BR /&gt;&lt;BR /&gt;I also have understood that HP-UX/Itanium is by default a stricter platform for C programmers than HP-UX/PA-RISC. I think there are some compiler options that can minimize the differences, but some of the old PA-RISC sloppiness absolutely must be fixed when porting the code to Itanium. See the porting guides provided by HP for details.&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Tue, 27 Jul 2010 21:26:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249245#M677727</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2010-07-27T21:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: strcmp different behaviour between HPUX and LINUX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249246#M677728</link>
      <description>There are two reasons why this works on HP-UX.&lt;BR /&gt;1) The default is -Z, which allows NULL pointer dereferences.  Use -z to abort.&lt;BR /&gt;2) strcmp has been extended to check for NULL pointers.&lt;BR /&gt;&lt;BR /&gt;None of these lead to good programming practices or portable code.  :-(&lt;BR /&gt;&lt;BR /&gt;&amp;gt;this should explain why it works on HPUX.&lt;BR /&gt;&lt;BR /&gt;Exactly.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Now my question is about Linux behavior&lt;BR /&gt;&lt;BR /&gt;Linux is stricter here.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Does it means that the Linux implementation does not conform ANSI C?&lt;BR /&gt;&lt;BR /&gt;This is a quality of implementation issue, and has nothing to do with the Standard.  The program is illegal.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;MK: 1) that the uninitialized memory location assigned to store **x contains by default a bit pattern that is equivalent to a NULL pointer.&lt;BR /&gt;&lt;BR /&gt;For a global, this is practically guaranteed.  Especially for C++.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;But later this has been found to encourage sloppy thinking and sloppy coding. &lt;BR /&gt;&lt;BR /&gt;Right.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I also have understood that HP-UX/Integrity is by default a stricter platform for C programmers than HP-UX/PA-RISC.&lt;BR /&gt;&lt;BR /&gt;Only because the aC++ compiler is newer.</description>
      <pubDate>Tue, 27 Jul 2010 22:33:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249246#M677728</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-07-27T22:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: strcmp different behaviour between HPUX and LINUX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249247#M677729</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I think that we can summarize the answer to my question by saying that:&lt;BR /&gt;&lt;BR /&gt;1. both HPUX and Linux strcmp implementations complie with ANSI C standard.&lt;BR /&gt;&lt;BR /&gt;2. HPUX implementation adds some specific features, like the NULL pointers managemet.&lt;BR /&gt;&lt;BR /&gt;Many thanks&lt;BR /&gt;&lt;BR /&gt;Giuseppe&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Jul 2010 06:40:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249247#M677729</guid>
      <dc:creator>Fedele Giuseppe</dc:creator>
      <dc:date>2010-07-28T06:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: strcmp different behaviour between HPUX and LINUX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249248#M677730</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I think that we can summarize the answer to my question by saying that:&lt;BR /&gt;&lt;BR /&gt;1. both HPUX and Linux strcmp implementations complie with ANSI C standard.&lt;BR /&gt;&lt;BR /&gt;2. HPUX implementation adds some specific features, like the NULL pointers managemet.&lt;BR /&gt;&lt;BR /&gt;Many thanks&lt;BR /&gt;&lt;BR /&gt;Giuseppe</description>
      <pubDate>Wed, 28 Jul 2010 06:41:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249248#M677730</guid>
      <dc:creator>Fedele Giuseppe</dc:creator>
      <dc:date>2010-07-28T06:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: strcmp different behaviour between HPUX and LINUX</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249249#M677731</link>
      <description>&lt;!--!*#--&gt;And:&lt;BR /&gt;&lt;BR /&gt;3. Code which relies on dereferencing NULL&lt;BR /&gt;pointers (or on any uninitialized values) is&lt;BR /&gt;asking for trouble.</description>
      <pubDate>Wed, 28 Jul 2010 09:55:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/strcmp-different-behaviour-between-hpux-and-linux/m-p/5249249#M677731</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-07-28T09:55:25Z</dc:date>
    </item>
  </channel>
</rss>

