Post subject: Questions about Objective-c, basic stuff (maybe!)
Former player
Joined: 4/16/2004
Posts: 1276
Location: Uppsala, Sweden
I have a few questions about Objective-C if anyone is familiar with that? At work I'm debugging obj-c code for some test cases, my knowledge of it is however not too deep yet. Anyway, a few test cases has started to fail because the system is adding a time stamp to the output file. The new output file will then always differ with the correct file in comparison since the correct file does not have this time stamp. So far so good and everything is logical and nice, but now I'm trying to find the cause of this time stamp issue, which has proven to be not so easy. My gut feeling tells me that the source of this problem is either in NSDate.h or CFDate.h files (NS = Foundation Class and CF = CoreFoundation type, http://en.wikipedia.org/wiki/Property_list). What I can't figure out is what the difference between those two are. I can't provide any code unfortunately since it's a company with security rules and stuff. But this NSDate should be, and looks to me who is utterly noobish, like basic stuff with a Gregorian Time Calender and so on. And had anyone seen a similar bug perhaps? Everything worked fine two weeks ago when the time stamp suddenly appeared for no reason. No one should have made changes to that part of the code either. Big thanks in advance for any help or tips!
/Walker Boh
Post subject: Re: Questions about Objective-c, basic stuff (maybe!)
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
Walker Boh wrote:
I have a few questions about Objective-C if anyone is familiar with that?
I currently develop for the iPhone for a living, so I'm somewhat familiar with Objective-C out of necessity.
Anyway, a few test cases has started to fail because the system is adding a time stamp to the output file. The new output file will then always differ with the correct file in comparison since the correct file does not have this time stamp. So far so good and everything is logical and nice, but now I'm trying to find the cause of this time stamp issue, which has proven to be not so easy.
I don't really understand what you mean by "time stamp". What "time stamp"? Where is it adding it? Among the data being written to the file (because that's the only way that the contents of a file could differ)? Please be more specific. A small example (of what you should be getting and what you are getting instead) could be helpful.
Former player
Joined: 4/16/2004
Posts: 1276
Location: Uppsala, Sweden
Certainly, my bad writing that last night before going home. Questions while being dead tired often fails. Let's say a test produce output to a log-file like: 1 2 3 Now however, for some unknown reason, the output is: 2010-01-12 07:56:27.155 +0100 1 2 3. What I've tried to do to eliminate this is to backtrace through the included header files and eliminate any further #include that has something to do with the time, for example NSDate and CFDate. Unfortunately nothing seems to help so far. I also don't have any fancier debug tools than winmake, which makes this a bit harder. So I can change some piece of the code, compile and see if I was right, then re-do it if I didn't succeed. I do realise that without the code this might be impossible to solve like this, I just figured it might be worth a shot if anyone had any idea at all. In any case, I hope this made it a bit clearer and thank you very much for your help regardless!
/Walker Boh
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
What function are you using to write to the file? For example NSLog() does always include a timestamp on each written line (on purpose). It's not supposed to be used to write data files, only to write actual log files (with timestamps on each line). If you want to write "raw" data to a file, use the C functions in stdio.h for that.
Former player
Joined: 4/16/2004
Posts: 1276
Location: Uppsala, Sweden
Allright, I'm on the right track now I think. I've found the source code for the time stamp finally. I'm not sure if this will solve it though since it seems to be some weirdness with memory handling. I'll see what I can do with it. Big thanks for the help anyway Warp!
/Walker Boh
Former player
Joined: 2/19/2007
Posts: 424
Location: UK
I'm not familiar with Objective-C at all, but if the C functions are available, then, as warp said, you can just use the functions from <stdio>:
#include <stdio>

void foo()
{
    FILE * file = fopen("example.txt","w");
    fprintf(file, "There are %d %s%s taller than %lf km on your %s\n",
        77, "beaver", 77 > 1 ? "s" : "", 0.831, "nose");
    fclose(file);
}