• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Compiler Sometimes Not Handling Escape Sequences in C-Strings?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Compiler Sometimes Not Handling Escape Sequences in C-Strings?


  • Subject: Re: Compiler Sometimes Not Handling Escape Sequences in C-Strings?
  • From: Larry Bright <email@hidden>
  • Date: Mon, 28 Aug 2006 09:49:00 -0700


Cameron,

Thanks very much for your reply. I examined the executable with hexdump as you suggested. I did not find the strings from my fprintf() statements in the executable file, but did find them a lib file (I put legacy C code [with suffix .m] in a lib of its own). In the library (.a) file the \n's in question are missing altogether! They do not appear as sequences of two ordinary ASCII's (reverse-slash + letter n), nor have they been transformed to one-byte 0x0a!! I'm amazed and more confused than ever!

Spurred on by these results, I created a new class as follows: 

@implementation TestFileWriter
- (void) writeIt
{
    FILE *oFile = fopen( "/Users/larry/Desktop/writeAwayTestFile", "w" );
    fprintf( oFile, "Test line %d:\n", 1 );
    fprintf( oFile, "Test line %d:\n", 2 );
    fclose( oFile );
}
@end

I then created a TestFileWriter instance (in the Python part of my code) and invoked the 'writeIt' method on it. This is similar to the original problem code except that the file is now written by a method of a class rather than by a global function. Also, the TestFileWriter code does not get library-ized ("librarified"?) as does the original file-writing code. Guess what! The problem disappears! The output file from TestFileWriter has the right number of lines, separated by 0x0a just as intended. 

Is there any reasonable explanation for this behavior, or have I found a bug in Xcode or related compiler/linkers/etc.? Additional insight from you or other Xcode Users would be much appreciated. 

Cheers,

Larry


On Aug 28, 2006, at 12:09 AM, Cameron Hayne wrote:

On 27-Aug-06, at 9:53 PM, Larry Bright wrote:

All the escaped newline characters appear as two characters in the file - backslash followed by lower-case letter n. I have searched the online documentation, re-read my most basic C  books to confirm that I'm not crazy and I still have no idea why the "escaping" of the newline does not work.

Look at the compiled executable with 'hexdump -C' and see if the "\n" characters appear in the executable as 0xa
They should.
For example:
% cat hello_world.c
#include <stdio.h>

int main()
{
    printf("Hello World\n");
    return 0;
}

% hexdump -C hello_world | grep Hello
00001e20  48 65 6c 6c 6f 20 57 6f  72 6c 64 0a 00 00 00 00  |Hello World.....|

--
Cameron Hayne
email@hidden



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Compiler Sometimes Not Handling Escape Sequences in C-Strings? (From: Larry Bright <email@hidden>)
 >Re: Compiler Sometimes Not Handling Escape Sequences in C-Strings? (From: Cameron Hayne <email@hidden>)

  • Prev by Date: Re: Visual Studio-style indent
  • Next by Date: Re: Visual Studio-style indent
  • Previous by thread: Re: Compiler Sometimes Not Handling Escape Sequences in C-Strings?
  • Next by thread: Help get started with the Accelerate Framework
  • Index(es):
    • Date
    • Thread