Pre-Lab 1 reading and notes

Command Line Processing

g++ -O3 myfile.cpp -o myprog

g++ is the command, everything else is a command line option

  • "-O3": optimization

  • "myfile.cpp": source file

  • "-o myprog": output executable into a file named "myprog"

Running the program: ./myprog -m resize

  • ./myprog: run
  • -m resize: do resize

In general "--anexample" is long-form and "-a" is short-form

Using getopt_long() - STL

1) #include at the top of your program

2) Create a data structure consisting of an array of type option, and initialize it correctly

3) Run a loop, calling getopt_long() until it signals there’s nothing more to process

a) Interpret each option

b) Process any additional arguments that go along with the options (such as “-m resize”: the “-m” is the option, and “resize” is its argument)

Long_options variable - data structure to hold the array for getopt?

The long_options variable is an array of option structures and each structure contains 4 parts:

1) A double-quoted C-string containing the long version of the option

2) A flag to indicate whether this option has an arguments that follow it (more on this soon)

3) A nullptr (which indicates that it should not store the option in some other variable)

4) A single-quoted character containing the short version of the option

a final one containing { nullptr, 0, nullptr, '\0' }

results matching ""

    No results matching ""