Monday, August 9, 2010

using tmpnam is dangerous. Use mkstemp

Whenever I used tmpnam my g++ compiler cribbed that its dangerous to use tmpnam and must use mkstemp. But mkstemp returned file id and as my language is C++, i never knew how to use the C file ids with C++ fstreams. Then I found out from the man page of fstream that,

explicit basic_ofstream(int fd);
explicit basic_ofstream(const char *s,
ios_base::openmode mode =
long protection = 0666);

I was familiar with the second usage but the first usage was new to me...So one can easily use ofstream with mkstemp as shown below.

char *tmpFileName= strdup("/tmp/tmpfileXXXXXX");
if(mkstemp(tmpFileName) == -1)
throw runtime_error("temporary file cannot be created");
ofstream out(tmpFileName);

Enjoy C++

Thursday, August 5, 2010

C/C++ interface for gnuplot

I think the C interface by N.Devillard is great! I just used it in my C++ code and it worked like a charm!

Please checkout gnuplot interfaces in ANSI C.

I also tried Gnuplot-iostream interface but somehow that did not work for me....


It was a big relief to see git. At last, I need not maintain a central repository and the git commands seemed so simple....

Once I went back to an older version - alas, all the later versions were lost. After reading some books in git, I realised that I should have branched from an older version. Thus if you are planning to experiment, it is better to branch to a new branch and experiment. If the experiment is successful, you can merge back into main stream. So easy!

The branch command is:

git branch branch_name tag_name(or commit hash)

to checkout the branch

git checkout branch_name

It is extremely comfortable to checkout branch and then merge into...

git merge for merging and for visualization of log, one can use
git log --graph --pretty=oneline --abbrev-commit

Now the eclipse git plugin provides branche/merge etc...making life more comfortable!

Thank you Linus Torvalds