Archive for November, 2009

Random Pics

Misc C++ links

C++ file I/O quick notes.

Sanskrit Tutor

An online Sanskrit tutor developed by IIT Madras. Acharya – Learn Sanskrit through self study.

Gcc and uninitialized variables

Gcc will not produce any warnings about uninitialized variables if the optimization level is not 1 or greater. The following code has an obvious uninitialized variable problem.

test.c

int foo() {
    int x;
    return x;
}

But gcc (3.4 and 4.2.1) produces no warning or error when you use this command line:

gcc -Wall -Werror -O0 test.c
gcc -Wall -Werror  test.c (this defaults to -O0)

I have tested the above on Linux as well as Mac OS X.
The -Wall flag is supposed to automatically include the -Wuninitialized flag. But if the optimization level is 0 then the check for uinitialized variables is not done.

gcc -Wall -Werror -Wuninitialized test.c

If included explicitly like above:

$ gcc -Wall -Werror -Wuninitialized test.c
cc1: warnings being treated as errors
cc1: warning: -Wuninitialized is not supported without -O

For gcc to check for uninitialized variables you need to throw at least -O1 optimization.

From the gcc man page:

-Wuninitialized
Warn if an automatic variable is used without first being
initialized or if a variable may be clobbered by a “setjmp” call.

These warnings are possible only in optimizing compilation, because
they require data flow information that is computed only when
optimizing. If you do not specify -O, you will not get these
warnings. Instead, GCC will issue a warning about -Wuninitialized
requiring -O.

However, uninitialized checking does not seem to work correctly. This code compiles on Mac OS X (Snow Leopard):

#include <stdlib.h>
#include <iostream>

int main() {

    int l_retVal;
    unsigned int x = 1;
    unsigned int y = random() % 10;
    if(y == x) {
        l_retVal = 2;
        std::cout<<"HERE \n";
    }
    return l_retVal;
}

$ g++ -Wall -Werror -Wuninitialized -O test.cpp
$

Easy Auto

Dial an auto in Bangalore – easyauto

BeeDocs Timeline

Timeline: An interesting Mac OS X App that lets you draw timelines in a cool way. The videos on the site dont seem to work (on Firefox). Works on Leopard.

CPU, Graphics, Stream computing, and OpenCL

  • NVIDIA GPU Gems1 book online
  • NVIDIA GPU Gems2 book (discusses GPU architecture) online

OpenCL Links

Code Markup – Wordpress plugin

  • Allows you to add nicely formatted code in your posts. Here and here.
  • Also see Dean’s Code Highlighter here.

Command line parsing in C++ – Tclap

TCLAP library

Let Me Google That For You

Let Me Google That For You