COMS W3157 Advanced Programming (AP)

  • Take notes on the possible contents of paper that are allowed to be brought in.

bash

  • opt
  • var symbols

heap/stack

  • arguments for execl

Traps

  • fork in while loop

    • Continuously branching out
  • Even if incremented inside a function, the original variable does not change

  • exec finishes the code once it is executed

  • Even if the incremented value is freed, it may be NULL

  • Variables created on the stack within a function call disappear when the scope is exited

  • fwrite outputs binary

    • Use “rb” instead of “r”
    • I want to confirm this
  • If the system is already big-endian, we won’t swap the bytes. If the system is little-endian, we swap the bytes to make them big-endian

  • If reading something other than a string, use “rb” instead of “r”, “wb” instead of “w”

  • When dealing with files, don’t forget to close them

  • argv[argc] = Null Pointer (*char) = NULL

    • NULL = false
  • socket, bind, connect, listen, accept

  • valgrind error types

  • c pointer struct union

TypeStorage sizeValue range
char1 byte-128 to 127 or 0 to 255
unsigned char1 byte0 to 255
signed char1 byte-128 to 127
int4 bytes-32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int4 bytes0 to 65,535 or 0 to 4,294,967,295
short2 bytes-32,768 to 32,767
unsigned short2 bytes0 to 65,535
long8 bytes or (4bytes for 32 bit OS)-9223372036854775808 to 9223372036854775807
unsigned long8 bytes0 to 18446744073709551615

1 byte = 8 bit = 2^8 pattern = 256 pattern = 16 ^ 2 pattern = 0x00~0xff

Big little endian check and convert

host = linux: little endian network = tcp/ip: big endian

listen

  • non-blocking

bind

  • client is not necessary

1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216,

In order to find the negative binary representation of a number n, you will need to flip all of the bits (in C, you can use the negation operator ’~’ to do this) and add 1.