Sunday, September 8, 2013

Function Pointers and Callback in C

http://www.linuxforu.com/2012/02/function-pointers-and-callbacks-in-c-an-odyssey/

http://www.learncpp.com/cpp-tutorial/78-function-pointers/

typedef....

Using name space and scope

http://stackoverflow.com/questions/223021/whats-the-scope-of-the-using-declaration-in-c

The scope of the using statement depends on where it is located in the code:
  • Placed at the top of a file, it has scope throughout that file.
  • If this is a header file, it will have scope in all files that include that header. In general, this is "not a good idea" as it can have unexpected side effects
  • Otherwise the using statement has scope within the block that contains it from the point it occurs to the end of the block. If it is placed within a method, it will have scope within that method. If it is placed within a class definition it will have scope within that class.

http://stackoverflow.com/questions/1677778/why-enclose-blocks-of-c-code-in-curly-braces

http://stackoverflow.com/questions/2759371/in-c-do-braces-act-as-a-stack-frame

void foo(int[]);
void bar(void);
void foobar(int); 

void foobar(int flag) {
    if (flag) {
        int big[100000000];
        foo(big);
    }
    bar();
}
gives:
_foobar:
    pushl   %ebp
    movl    %esp, %ebp
    movl    $400000008, %eax
    call    __alloca
    cmpl    $0, 8(%ebp)
    je      L2
    leal    -400000000(%ebp), %eax
    movl    %eax, (%esp)
    call    _foo
L2:
    call    _bar
    leave
    ret

Friday, August 23, 2013

sync folders over remote placeT

http://www.finiteloops.com/weblog/?p=111

rsync -avze ssh /localpath(source)/ user@remoteaddress:/remotepath/(destination)

Tuesday, August 20, 2013

Static Library .a and Dynamic Library .so

http://www.ilkda.com/compile/Static_Versus_Dynamic.htm


Creating .so and .a in Unix
http://stackoverflow.com/questions/1648215/creating-so-and-a-in-unix

Sunday, August 18, 2013

gcc warning: function used but not defined

static

internal linkage

http://stackoverflow.com/questions/5526461/gcc-warning-function-used-but-not-defined

warning: format not a string literal and no format arguments

This warning is gcc's way of telling you that it cannot verify the format string argument to the printf style function (printf, fprintf... etc). This warning is generated when the compiler can't manually peek into the string and ensure that everything will go as you intend during runtime. Lets look at a couple of examples.
Case 1. This string can be verified at compile time and the compiler will allow it without warning:
printf("This string has no format");
Case 2: For this case, the compiler can detect that you have a format specifier and will raise a different warning. On my machine it said "warning: too few arguments for format".
// This will most probably crash your machine
printf("Not a safe string to %s"); 
Case 3. Now this is somewhat your case. You are taking a string generated at runtime and trying to print it. The warning you are getting is the compiler warning you that there could be a format specifier in the string. Say for eg "bad%sdata". In this case, the runtime will try to access a non-existent argument to match the %s. Even worse, this could be a user trying to exploit your program (causing it to read data that is not safe to read).
char str[200];
scanf("%s", str)
printf(str)
 http://stackoverflow.com/questions/4419293/warning-format-not-a-string-literal-and-no-format-arguments