Information in the executable file which is useful

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: c and create an executable named hello: g++ hw.c -o hello •  If you want to include symbolic information in the executable file which is useful for debugging, add the -g flag: g++ -g hw.c -o hello •  If your C++ program involves several files, you can compile them separately, and link them to produce an executable file. More on that later! Scott B. Baden / CSE 100, Lec 2 / Spring 2013 43 Today’s Lecture •  An introduction to C++ •  Comparing Java and C++ •  Basic C++ programming •  Pointers and pointer arithmetic •  Pragmatics – quickly quickly, read the book & slides •  C++ primitive types and operators •  Reading: Weiss Ch 1, section 1.4 to 1.7 Scott B. Baden / CSE 100, Lec 2 / Spring 2013 44 C++ primitive types •  The C++ language provides these basic types •  integer types (these are signed; put unsigned in front to specify unsigned): char short int long bool •  at least 8 bits (it’s exactly 8 bits on every platform I’m aware of) at least 16 bits at least as large as short (16 bits on DOS and Win 3.1, 32 bits elsewhere) at least 32 bits 8 bits, holds values true and false, behaves like an int (1 and 0) floating-point types: float ~7 decimal digits of precision and magnitude 10-38 to 1038 double ~15 decimal digits of precision and magnitude 10-308 to 10308 •  Handy reference @ http://en.cppreference.com/w/cpp/language/types •  You can also create types based on these basic types and on user-defined types: •  pointers •  classes, structures and unions •  arrays •  enumerations Scott B. Baden / CSE 100, Lec 2 / Spring 2013 45 The size of variables in C++ •  •  •  •  C++ doesn’t specify the size of its types as precisely as Java does For example, an int in a C++ program might be 16 bits, or 32 bits, or even 64 bits C++ provides a way to tell how much memory a type takes: the sizeof operator For any typename T (even a user-defined type), the expression sizeof(T) has an integer value equal to the number of bytes (not bits) that it takes to store a variable of type T •  For any variable x, the expression sizeof(x) has an integer value equal to the number of bytes that it takes to store x •  So, for example, on a typical UNIX system, in a C program with this declaration: int num; what would be the values of these expressions? sizeof(int) sizeof(num) Scott B. Baden / CSE 100, Lec 2 / Spring 2013 46 Variable declaration statements in C++ •  V ariable declaration statements in C++ have a syntax basically similar to Java •  However, they have very different semantics in some cases •  For example, suppose C is the name of a class. Then: •  Java declares x to be of type C, but doesn’t create an object instance of class C C x; (It creates a pointer that can point to such an object, but does not create any object.) •  On the other hand, in C++: C x; declares x to be of type C, and creates an object that is an instance of the class C, u...
View Full Document

This note was uploaded on 09/11/2013 for the course CSE 100 taught by Professor Staff during the Spring '08 term at UCSD.

Ask a homework question - tutors are online