Hank Childs (LBNL) and Charles Doutriaux (LLNL) September 22, 2011
Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __...
-
Upload
bartholomew-owens -
Category
Documents
-
view
215 -
download
0
Transcript of Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __...
![Page 1: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/1.jpg)
Hank Childs, University of OregonJune 3rd, 2015
CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / / __ \/ / |/_/ / __ `/ __ \/ __ / / / _/_// / __/ /___/ /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / /____/_/ / /__/_ __/_ __/ \____/_/ /_/_/_/|_| \__,_/_/ /_/\__,_/ \____/_/ \____//_/ /_/
Lecture 19:templates and
the standard template library
![Page 2: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/2.jpg)
Outline
• Announcements• Special Topics• Review• Potpourri from Lec 17• Templates• Standard Template Library• C++ Strings• Bonus Slides
![Page 3: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/3.jpg)
Outline
• Announcements• Special Topics• Review• Potpourri from Lec 17• Templates• Standard Template Library• C++ Strings• Bonus Slides
![Page 4: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/4.jpg)
Announcements: Projects
• 3G: due Monday• 3H: due “Friday”• 4B: due “Friday”• 4C: due “Friday”• “Friday” not late until June 11th
• And: all work must be turned by June 11th
• And: Project 3 grading may be simplified
![Page 5: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/5.jpg)
Announcements: Logistics
• Office Hours: right here after class• Lab: no Lab this week!• Final: Monday June 8th @ 2:45pm in this room• Grading…
![Page 6: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/6.jpg)
Outline
• Announcements• Special Topics• Review• Potpourri from Lec 17• Templates• Standard Template Library• C++ Strings• Bonus Slides
![Page 7: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/7.jpg)
Special Topics
• Virtual functions in constructors• const Image with Update
![Page 8: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/8.jpg)
Outline
• Announcements• Special Topics• Review• Potpourri from Lec 17• Templates• Standard Template Library• C++ Strings• Bonus Slides
![Page 9: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/9.jpg)
“this”: pointer to current object
• From within any struct’s method, you can refer to the current object using “this”
![Page 10: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/10.jpg)
How methods work under the covers (4/4)
Addr. Variable Value
0x8000 MIC/myInt
12
Addr. Variable Value
0x8000 MIC/myInt
12
0x8004 mic 0x8000
Addr. Variable Value
0x8000 MIC/myInt
12
Addr. Variable Value
0x8000 MIC/myInt
12
0x8004 this 0x8000
The compiler secretly slips “this” onto the stack whenever you make a
method call.
It also automatically changes “myInt” to this->myInt in methods.
![Page 11: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/11.jpg)
Picking the right virtual function
??????
So how to does the compiler know?
How does it get “B” for “b” and “A” for “a”?
![Page 12: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/12.jpg)
Virtual Function Table
• Let C be a class and X be an instance of C.• Let C have 3 virtual functions & 4 non-virtual
functions• C has a hidden data member called the “virtual
function table”• This table has 3 rows– Each row has the correct definition of the virtual
function to call for a “C”.• When you call a virtual function, this table is
consulted to locate the correct definition.
![Page 13: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/13.jpg)
Virtual Function Table
• Let C be a class and X be an instance of C.• Let C have 3 virtual functions & 4 non-virtual
functions• Let D be a class that inherits from C and Y be
an instance of D.– Let D add a new virtual function
• D’s virtual function table has 4 rows– Each row has the correct definition of the virtual
function to call for a “D”.
![Page 14: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/14.jpg)
More notes on virtual function tables
• There is one instance of a virtual function table for each class– Each instance of a class shares the same virtual
function table• Easy to overwrite (i.e., with a memory error)– And then all your virtual function calls will be
corrected– Don’t do this! ;)
![Page 15: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/15.jpg)
Calling a virtual function
• Let X be an instance of class C.• Let the virtual function be the 4th function• Let the arguments to the virtual function be
an integer Y and a float Z.• Then call:
(X.vptr[3])(&X, Y, Z);
The pointer to the virtual function pointer (often called a vptr) is a data member of X
The 4th virtual function has index 3 (0-indexing)
Secretly pass “this” as first argument to method
![Page 16: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/16.jpg)
Inheritance and Virtual Function TablesA
Foo1 Location of Foo1
B
Foo1 Location of Foo1
Foo2 Location of Foo2
C
Foo1 Location of Foo1
Foo2 Location of Foo2
Foo3 Location of Foo3
Same as B’sThis is how you can treat a C as a B
This whole scheme gets much harder with virtual inheritance, and you have to carry around multiple
virtual function tables.
: public B
![Page 17: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/17.jpg)
Virtual Function Table: Summary
• Virtual functions require machinery to ensure the correct form of a virtual function is called
• This is implemented through a virtual function table
• Every instance of a class that has virtual functions has a pointer to its class’s virtual function table
• The virtual function is called via following pointers– Performance issue
![Page 18: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/18.jpg)
Upcasting and Downcasting
• Upcast: treat an object as the base type– We do this all the time!– Treat a Rectangle as a Shape
• Downcast: treat a base type as its derived type– We don’t do this one often– Treat a Shape as a Rectangle• You better know that Shape really is a Rectangle!!
![Page 19: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/19.jpg)
Upcasting and Downcasting
what do we get?
![Page 20: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/20.jpg)
Upcasting and Downcasting
• C++ has a built in facility to assist with downcasting: dynamic_cast
• I personally haven’t used it a lot, but it is used in practice
• Ties in to std::exception
![Page 21: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/21.jpg)
Default Arguments
default arguments: compiler pushes values on the stack for you if you choose not to enter them
![Page 22: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/22.jpg)
Booleans
• New simple data type: bool (Boolean)• New keywords: true and false
![Page 23: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/23.jpg)
gettimeofday example
![Page 24: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/24.jpg)
Outline
• Announcements• Special Topics• Review• Potpourri from Lec 17• Templates• Standard Template Library• C++ Strings• Bonus Slides
![Page 25: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/25.jpg)
Inline function
• inlined functions:– hint to a compiler that can
improve performance– basic idea: don’t actually
make this be a separate function that is called• Instead, just pull the code
out of it and place it inside the current function
– new keyword: inlineThe compiler sometimes refuses your inline request (when it thinks
inlining won’t improve performance), but it does it silently.
![Page 26: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/26.jpg)
Inlines can be automatically done within class definitions
• Even though you don’t declare this as inline, the compiler treats it as an inline
![Page 27: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/27.jpg)
You can do inlines within header files, but not regular functions
Left: function is inlined in every .C that includes it … no problem
Right: function is defined in every .C that includes it … duplicate symbols
![Page 28: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/28.jpg)
Outline
• Announcements• Special Topics• Review• Potpourri from Lec 17• Templates• Standard Template Library• C++ Strings• Bonus Slides
![Page 29: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/29.jpg)
Motivation
![Page 30: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/30.jpg)
Motivation
![Page 31: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/31.jpg)
First Template
![Page 32: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/32.jpg)
Will now do an example to compare templates and virtual functions
• Will take some buildup…
![Page 33: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/33.jpg)
Money Class
![Page 34: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/34.jpg)
License Plate Class
![Page 35: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/35.jpg)
Sorting With Templates
![Page 36: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/36.jpg)
Doing the same with inheritance
![Page 37: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/37.jpg)
Templates vs Virtual Functions
• Virtual functions:– Had to affect inheritance hierarchy– Overhead in function call (virtual function table)
• Templates:– Did not need to affect inheritance hierarchy,
although function names had to coincide– No additional overhead (resolved at compile time)
![Page 38: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/38.jpg)
Outline
• Announcements• Special Topics• Review• Potpourri from Lec 17• Templates• Standard Template Library• C++ Strings• Bonus Slides
![Page 39: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/39.jpg)
Standard Template Library
• Standard Template Library: STL• Many, many templated types• Can ease your programming• Can also hide significant performance issues– And you use C/C++ for performance
• My recommendation: use with caution for code that needs to be performant
![Page 40: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/40.jpg)
Vector
![Page 41: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/41.jpg)
std::vector
• Always has the amount of memory you need• Many STL algorithms work on it• Memory allocation:– If you don’t have enough, double it• (can be a big overestimation)
• Overhead in access– Maybe not a big deal if data-intensive?
![Page 42: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/42.jpg)
STL: map
![Page 43: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/43.jpg)
Outline
• Announcements• Special Topics• Review• Potpourri from Lec 17• Templates• Standard Template Library• C++ Strings• Bonus Slides
![Page 44: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/44.jpg)
(not a template thing): String
• C++ string class is very useful• Great implementation of a class that
encapsulates a string
![Page 45: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/45.jpg)
String methods
![Page 46: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/46.jpg)
String methods
![Page 47: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/47.jpg)
Outline
• Announcements• Special Topics• Review• Potpourri from Lec 17• Templates• Standard Template Library• C++ Strings• Bonus Slides
![Page 48: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/48.jpg)
Backgrounding
• “&”: tell shell to run a job in the background– Background means that the shell acts as normal,
but the command you invoke is running at the same time.
• “sleep 60” vs “sleep 60 &”
When would backgrounding be useful?
![Page 49: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/49.jpg)
Suspending Jobs
• You can suspend a job that is runningPress “Ctrl-Z”
• The OS will then stop job from running and not schedule it to run.
• You can then:– make the job run in the background.
• Type “bg”
– make the job run in the foreground.• Type “fg”
– like you never suspended it at all!!
![Page 50: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/50.jpg)
printf
• Print to stdout– printf(“hello world\n”);– printf(“Integers are like this %d\n”, 6);– printf(“Two floats: %f, %f”, 3.5, 7.0);
Have you ever wondered how printf takes a variable number of arguments?
![Page 51: Hank Childs, University of Oregon June 3 rd, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649e025503460f94aed89d/html5/thumbnails/51.jpg)
Variable-Length Argument Lists
Adapted from Kernigan & Ritchie C book