C

Today's g++/C++ funny: ofstream's open constructor

Tags: •  •  • 

So, I’m working on a project, and have some code like this:

string blah="somefile"; ofstream fp;

fp.open(blah);

And it doesn’t work. Apparently, what you need to do when using ofstream’s open method:

fp.open(blah.c_str());

Yes, it looks like what it is. Apparently g++’s iostreams library (gcc 3.2) does not support things that have been part of the C++ standard for years—like C++ STL strings… You have to convert back to a C string.

Last I checked this was 2005, not 1999. You’d have thought someone would have overloaded this by now… I’ve only checked this in g++; will check with Intel’s C++ compiler and Microsoft Visual Studio later, though I’m not sure whether to expect better. What didn’t help me to find this out, of course, is g++’s totally wonderful (sarcasm) compiler error messages…


The semantics of a fork, followed by setsid, and another fork

Tags: •  • 

So I came across a piece of code that looked like this:

if (fork() != 0) exit(0); setsid(); if (fork() != 0) exit(0);

What each individual system call can easily be looked up and understood (well, maybe not setsid), but what the entire block of code is doing is not clear at all

…and I really can’t say I understand the mechanics of it all to explain myself. But this python code segment’s comments does a good job of what the entire block of code is trying to do—daemonize a process completely.


Syndicate content