home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / amiga / programm / 16130 < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.2 KB  |  42 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!sunic!seunet!pop!bjst
  3. From: bjst@sth.frontec.se (Bjorn Stenberg)
  4. Subject: Re: What is wrong with this very simple c program?
  5. Message-ID: <1992Nov20.133457.678@sth.frontec.se>
  6. Nntp-Posting-Host: pop.sth.frontec.se
  7. Organization: IDK/Frontec - System Design Group
  8. References: <BxIpyB.E7@unx.sas.com> <johnv.03kr@acix.DIALix.oz.au>
  9. Date: 20 Nov 92 13:34:57 GMT
  10. Lines: 30
  11.  
  12. johnv@acix.DIALix.oz.au (John Verhoeven) writes:
  13. > Whats even more fun :-) is that in some compilers accessing arrays with
  14. > a negative subscript is also legal, eg foo[-1] = 5.
  15. > Does SAS C V6 allow this ?
  16.  
  17. It should! Check out this one:
  18.  
  19. main()
  20. {
  21.     char    String_AC [30];
  22.     char*    StrPtr_PC = NULL;
  23.  
  24.     strcpy( String_AC, "Hello world.\n" );
  25.     StrPtr_PC = &( String_AC[1] );
  26.  
  27.     if ( 'H' == StrPtr_PC[ -1 ] )
  28.         printf( "Found it!\n" );
  29.     else
  30.         printf( "Failed.\n");
  31. }
  32.  
  33. Somewhat dangerous if you're not cautious, but perfectly legal.
  34.  
  35.         -- Bjorn
  36.  
  37.  
  38.        ///  Bjorn Stenberg, Stockholm, Sweden         bjst@sth.frontec.se
  39.       ///  main() { printf(&unix["\021%six\012\0"],(unix)["have"]+"fun"-0x60);}
  40.  \\\ ///  "- Your documentation no longer confuses me, old version!"
  41.