Thinking in C and *nix (CSC 295/282 2014S) : Outlines
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [Teaching & Learning] - [Calendar]
Current: [Outline] [EBoard] [Lab] [Assignment]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines]
Reference: [EBook] - [ISO] [GNU Coding Standards] [GCC Documentation] - [TAoUP] [Make3]
Related Courses: [CSC 295 2013S]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
Held: Thursday, 1 May 2014
Back to Outline 12 - Miscellaneous C Programming Issues. On to Outline 14 - Wrapup.
Summary
We consider how to write C procedures that take a variable number (and type) of parameters.
Related Pages
Overview
Administrivia
printf and it's variants.
printf is int printf (char *format, ...);int *iarray (int v0, ...);va_list for
"the rest".va_list with va_start (rest, prevparam)
rest is our variable of type va_listprevparam is the name of the parameter that comes before
the ellipsesva_arg (rest, type)
type is the type of the parameterrestva_list, you create the copy with
va_copy (va_list dest, va_list src).int are promoted
to int; Floating point values are always double.[simonsays.c](../examples/varargs/simonsays.c) explores printing
multiple strings.[sum.c](../examples/varargs/sum.c explores summing floating point
values.[writer1.c](../examples/varargs/writer1.c) uses a printf-style approach.[writer2.c](../examples/varargs/writer2.c) uses a "prefix with types"
approach. (There's a particular type for "end of input".)__VAR_ARGS__.#define myprint(stuff...) printf (stuff).#define CALL(fun, params...) fun (params)
va_start points immediately "after" it's parameterva_arg advances the parameter[stack.c](../examples/varargs/stack.c) for
an exploration of the arrangement of the stack.Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [Teaching & Learning] - [Calendar]
Current: [Outline] [EBoard] [Lab] [Assignment]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines]
Reference: [EBook] - [ISO] [GNU Coding Standards] [GCC Documentation] - [TAoUP] [Make3]
Related Courses: [CSC 295 2013S]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
Copyright (c) 2013-14 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.