Monday, April 21, 2014

powercfg: Windows

Let's say you're able to change the power configuration from the GUI, you call use the following commands (e.g. powershell) to override the current configuration. 

powercfg -change -standby-timeout-ac 0
powercfg -change -hibernate-timeout-ac 0
powercfg -change -monitor-timeout-ac 0

Note:
0 (zero) or any number: set the computer to standby/hibernate/monitor sleep after this number of minutes idle.

Saturday, April 19, 2014

gcc and c99 mode

In Java, the standard "for loop" is that the counter i is declared inside the loop as follows:

for (int i=0; i < 10; i++){
    System.out.println("Hello, world!");
}

However, for C, if you try to declare the counter inside the for for loop:
for (int it=0; i<10;i++{
     printf("Hello, world!\n");
}

You may get this error:
for_loop_test.c: In function ‘main’:
for_loop_test.c:4: error: ‘for’ loop initial declaration used outside C99 mode

By default, the compiler gcc uses the ANSI c syntax (aka C89 mode), not ISO syntax (aka C99 mode). To turn on the C90 mode, add this argument to gcc
gcc -std=c99 foo.c


Note:
ANSI < American National Standard Institute
ISO < International Standard Organization

Thursday, April 10, 2014

cygwin: linux native for windows platform

Download and install cygwin (e.g. c:\cygwin)
Setup path variable for cygwin
Setup cygwin update
         setup-x86_64.exex
ifconfig command is not supported by cygwin, but the good news that you can use ipconfig!
dig command from the packages: bind-utils and curl

gdb and objdump: C debugger

By default, the assembly language for your machine may use ATT syntax, to set gdb use Intel syntax assembly language, use this command when in gdb:

         set disassembly intel (if not working, try this: set disassebmly-flavor intel)

You may try to configure this setting to run every time GDB start up by putting the command in the file .gdbinit in your home directory.

          echo "set disassembly-flavor intel" > ~/.gdbinit

To view the value at memory address (e.g. 0x1004010dd), use x (examine) command. This command requires 2 arguments: the memory address and the display format (o: octal, x: hex, u: base-10 decimal, t: binary).
          x/x 0x1004010dd

The x command may be also used to display assembly instruction at the memory address
         x/i 0x1004010dd (i short for instruction)

To use objdump*:
        objdump -D a.out
        objdump -M intel -D a.out (display with Intel syntax, otherwise AT&T syntax by default)

Note: * for Mac OSX, objdump is not installed by default. To install it, use this command:
       sudo port install binutils
And installation location: /opt/local/x86_64-apple-darwin11.3.0/bin