about summary refs log tree commit diff stats
path: root/dev/c/hello.html
blob: 14c65e9883ad0181740f04efecb85eb84e558536 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE html>
<html dir="ltr" lang="en">
    <head>
	<meta charset='utf-8'>
	<title>C &amp; GDB</title>
    </head>
    <body>
        <a href="index.html">C Index</a>

	<h1>Hello World</h1>

        <p>C "allows to implement" or approach to various
        programming paradigms but due to it's characteristics
        it's more a procedural language. C procedural programs
        are divided in smaller procedures, or functions, and
        data or pointers to data are passed into them or is
        shared between them. To get started create file
        hello.c with;</p>

	<pre>
	#include &lt;stdio.h&gt;

	int main() {
	    printf("Hello World!");
	    return 0;
	}
	</pre>

	<p>Compile;</p>

	<pre>
	$ gcc -Wall hello.c -o hello
	</pre>

	<p>Run;</p>

	<pre>
	$./hello
	Hello World!
	</pre>

	<h2 id="makefile">Makefile</h2>

	<p>Make reads a Makefile by default on current directory,
	Makefile defines targets, for example executables and their
	dependencies, for example object files and source files.<p>

	<p>Create Makefile;</p>

	<pre>
	CC=gcc
	CFLAGS=-Wall

	hello: main.o hello.o

	clean:
		rm -f hello main.o hello.o
	</pre>

	<pre>
	$ touch NEWS README AUTHORS ChangeLog
	</pre>

	<h2 id="debug">Debug</h2>

	<p>To use gdb you need to compile program with -g flag. Change
	Makefile</p>

	<pre>
	CC=gcc
	CFLAGS=-Wall -g

	hello: main.o hello.o

	clean:
		rm -f hello main.o hello.o
	</pre>

	<pre>
	$ gdb hello
	</pre>

	<p>Set break point;</p>

	<pre>
	(gdb) break main
	</pre>

	<p>To start the program you can type run, this way gdb
	will try to run the program until the end. If program
	crash, gdb will stop it for debuging. Start program;</p>

	<pre>
	(gdb) run
	</pre>

	<p>Step in next line;</p>

	<pre>
	(gdb) s
	</pre>

        <p>Print variable "name" value;</p>

        <pre>
        (gdb) print name
        $1 = 0x4005b0 "world"
        (gdb)
        </pre>

        <p>Print variable "name" type;</p>

        <pre>
        (gdb) ptype name
        type = const char *
        (gdb)
        </pre>

        <p>Variable is a <a href="elements.html#const">string constant</a>.
        Execute next line to end;</p>

	<pre>
	(gdb) n
	</pre>

        <a href="index.html">C Index</a>
	<p>
	This is part of the Hive System Documentation.
	Copyright (C) 2019
	Hive Team.
	See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
	for copying conditions.</p>
    </body>
</html>
ight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<HTML>
<HEAD>
<TITLE>Simply Scheme contents</TITLE>
<link rel="shortcut icon" href="http://www.cs.berkeley.edu/~bh/simply.png" type="image/png">
</HEAD>
<BODY>
<H1><CITE>Simply Scheme:<BR>Introducing Computer Science</H1>

<TABLE><TR><TD>
<P><IMG SRC="simply.jpg" ALT="cover photo">
<TD valign="center">
<CITE><A HREF="http://www.cs.berkeley.edu/~bh/">Brian
Harvey</A><BR><A HREF="http://www.cnmat.berkeley.edu/~matt">Matthew
Wright</A><BR>University of California, Berkeley</CITE>
<BR><BR><A HREF="http://www-mitpress.mit.edu/book-home.tcl?isbn=0262082810">MIT
Press web page for <CITE>Simply Scheme</CITE></A>
</TABLE>

<P><TABLE><TR><TD><A HREF="ss/foreword.html"><H3>Foreword</H3></A>
<TD>by Hal Abelson</TABLE>

<H3><A HREF="https://people.eecs.berkeley.edu/~bh/ss/preface">Preface</A></H3>
<UL>
<LI>One Big Idea: Symbolic Programming
<LI>Lisp and Radical Computer Science
<LI>Who Should Read This Book
<LI>How to Read This Book
</UL>

<H3><A HREF="ss/instructor.html">To the Instructor</A></H3>
<UL>
<LI>Lists and Sentences
<LI>Sentences and Words
<LI>Overloading in the Text Abstraction
<LI>Higher-Order Procedures, Lambda, and Recursion
<LI>Mutators and Environments
</UL>

<H3><A HREF="ss/ack.html">Acknowledgments</A></H3>

<P><EM>(Note: The links on the Part headings below point to the
introductions to the major parts of the book, each introducing one
"big idea."  Each introduction is about a page of text.)</EM>

<A HREF="part1.html"><H2>Part I. Introduction: Functions</H2></A>

<H3>1. Showing Off Scheme</H3>
<UL>
<LI>Talking to Scheme
<LI>Recovering from Typing Errors
<LI>Exiting Scheme
<LI>More Examples
<LI>Example: Acronyms
<LI>Example: Pig Latin
<LI>Example: Ice Cream Choices
<LI>Example: Combinations from a Set
<LI>Example: Factorial
<LI>Play with the Procedures
</UL>

<H3>2. Functions</H3>
<UL>
<LI>Arithmetic
<LI>Words
<LI>Domain and Range
<LI>More Types: Sentences and Booleans
<LI>Our Favorite Type: Functions
<LI>Play with It
<LI>Thinking about What You've Done
</UL>

<A HREF="part2.html"><H2>Part II. Composition of Functions</H2></A>

<H3>3. Expressions</H3>
<UL>
<LI>Little People
<LI>Result Replacement
<LI>Plumbing Diagrams
<LI>Pitfalls
</UL>

<H3>4. Defining Your Own Procedures</H3>
<UL>
<LI>How to Define a Procedure
<LI>Special Forms
<LI>Functions and Procedures
<LI>Argument Names versus Argument Values
<LI>Procedure as Generalization
<LI>Composability
<LI>The Substitution Model
<LI>Pitfalls
</UL>

<H3>5. Words and Sentences</H3>
<UL>
<LI>Selectors
<LI>Constructors
<LI>First-Class Words and Sentences
<LI>Pitfalls
</UL>

<H3>6. True and False</H3>
<UL>
<LI>Predicates
<LI>Using Predicates
<LI><CODE>If</CODE> Is a Special Form
<LI>So Are <CODE>And</CODE> and <CODE>Or</CODE>
<LI>Everything That Isn't False Is True
<LI>Decisions, Decisions, Decisions
<LI><CODE>If</CODE> Is Composable
<LI>Pitfalls
</UL>

<H3>7. Variables</H3>
<UL>
<LI>How Little People Do Variables
<LI>Global and Local Variables
<LI>The Truth about Substitution
<LI><CODE>Let</CODE>
<LI>Pitfalls
</UL>

<A HREF="part3.html"><H2>Part III. Functions as Data</H2></A>

<H3>8. Higher-Order Functions</H3>
<UL>
<LI><CODE>Every</CODE>
<LI>A Pause for Reflection
<LI><CODE>Keep</CODE>
<LI><CODE>Accumulate</CODE>
<LI>Combining Higher-Order Functions
<LI>Choosing the Right Tool
<LI>First-Class Functions and First-Class Sentences
<LI><CODE>Repeated</CODE>
<LI>Pitfalls
</UL>

<H3>9. Lambda</H3>
<UL>
<LI>Procedures That Return Procedures
<LI>The Truth about <CODE>Define</CODE>
<LI>The Truth about <CODE>Let</CODE>
<LI>Name Conflicts
<LI>Named and Unnamed Functions
<LI>Pitfalls
</UL>

<H3>Project: Scoring Bridge Hands</H3>

<H3>10. Example: Tic-Tac-Toe</H3>
<UL>
<LI>A Warning
<LI>Technical Terms in Tic-Tac-Toe
<LI>Thinking about the Program Structure
<LI>The First Step: Triples
<LI>Finding the Triples
<LI>Using <CODE>Every</CODE> with Two-Argument Procedures
<LI>Can the Computer Win on This Move?
<LI>If So, in Which Square?
<LI>Second Verse, Same as the First
<LI>Now the Strategy Gets Complicated
<LI>Finding the Pivots
<LI>Taking the Offensive
<LI>Leftovers
<LI>Complete Program Listing
</UL>

<A HREF="https://people.eecs.berkeley.edu/~bh/part4.html"><H2>Part IV. Recursion</H2></A>

<H3>11. Introduction to Recursion</H3>
<UL>
<LI>A Separate Procedure for Each Length
<LI>Use What You Have to Get What You Need
<LI>Notice That They're All the Same
<LI>Notice That They're Almost All the Same
<LI>Base Cases and Recursive Calls
<LI>Pig Latin
<LI>Problems for You to Try
<LI>Our Solutions
<LI>Pitfalls
</UL>

<H3>12. The Leap of Faith</H3>
<UL>
<LI>From the Combining Method to the Leap of Faith
<LI>Example: <CODE>Reverse</CODE>
<LI>The Leap of Faith
<LI>The Base Case
<LI>Example: <CODE>Factorial</CODE>
<LI>Likely Guesses for Smaller Subproblems
<LI>Example: <CODE>Downup</CODE>
<LI>Example: <CODE>Evens</CODE>
<LI>Simplifying Base Cases
<LI>Pitfalls
</UL>

<H3>13. How Recursion Works</H3>
<UL>
<LI>Little People and Recursion
<LI>Tracing
<LI>Pitfalls
</UL>

<H3>14. Common Patterns in Recursive Procedures</H3>
<UL>
<LI>The <CODE>Every</CODE> Pattern
<LI>The <CODE>Keep</CODE> Pattern
<LI>The <CODE>Accumulate</CODE> Pattern
<LI>Combining Patterns
<LI>Helper Procedures
<LI>How to Use Recursive Patterns
<LI>Problems That Don't Follow Patterns
<LI>Pitfalls
</UL>

<H3>Project: Spelling Names of Huge Numbers</H3>

<H3>15. Advanced Recursion</H3>
<UL>
<LI>Example: <CODE>Sort</CODE>
<LI>Example: <CODE>From-Binary</CODE>
<LI>Example: <CODE>Mergesort</CODE>
<LI>Example: <CODE>Subsets</CODE>
<LI>Pitfalls
</UL>

<H3>Project: Scoring Poker Hands</H3>
<UL>
<LI>Extra Work for Hotshots
</UL>

<H3>16. Example: Pattern Matcher</H3>
<UL>
<LI>Problem Description
<LI>Implementation: When Are Two Sentences Equal?
<LI>When Are Two Sentences Nearly Equal?
<LI>Matching with Alternatives
<LI>Backtracking
<LI>Matching Several Words
<LI>Combining the Placeholders
<LI>Naming the Matched Text
<LI>The Final Version
<LI>Abstract Data Types
<LI>Backtracking and <CODE>Known-Values</CODE>
<LI>How We Wrote It
<LI>Complete Program Listing
</UL>

<A HREF="part5.html"><H2>Part V. Abstraction</H2></A>

<H3>17. Lists</H3>
<UL>
<LI>Selectors and Constructors
<LI>Programming with Lists
<LI>The Truth about Sentences
<LI>Higher-Order Functions
<LI>Other Primitives for Lists
<LI>Association Lists
<LI>Functions That Take Variable Numbers of Arguments
<LI>Recursion on Arbitrary Structured Lists
<LI>Pitfalls
</UL>

<H3>18. Trees</H3>
<UL>
<LI>Example: The World
<LI>How Big Is My Tree?
<LI>Mutual Recursion
<LI>Searching for a Datum in the Tree
<LI>Locating a Datum in the Tree
<LI>Representing Trees as Lists
<LI>Abstract Data Types
<LI>An Advanced Example: Parsing Arithmetic Expressions
<LI>Pitfalls
</UL>

<H3>19. Implementing Higher-Order Functions</H3>
<UL>
<LI>Generalizing Patterns
<LI>The <CODE>Every</CODE> Pattern Revisited
<LI>The Difference between <CODE>Map</CODE> and <CODE>Every</CODE>
<LI><CODE>Filter</CODE>
<LI><CODE>Accumulate</CODE> and <CODE>Reduce</CODE>
<LI>Robustness
<LI>Higher-Order Functions for Structured Lists
<LI>The Zero-Trip Do Loop
<LI>Pitfalls
</UL>

<A HREF="part6.html"><H2>Part VI. Sequential Programming</H2></A>

<H3>20. Input and Output</H3>
<UL>
<LI>Printing
<LI>Side Effects and Sequencing
<LI>The <CODE>Begin</CODE> Special Form
<LI>This Isn't Functional Programming
<LI>Not Moving to the Next Line
<LI>Strings
<LI>A Higher-Order Procedure for Sequencing
<LI>Tic-Tac-Toe Revisited
<LI>Accepting User Input
<LI>Aesthetic Board Display
<LI>Reading and Writing Normal Text
<LI>Formatted Text
<LI>Sequential Programming and Order of Evaluation
<LI>Pitfalls
</UL>

<H3>21. Example: The <CODE>Functions</CODE> Program</H3>
<UL>
<LI>The Main Loop
<LI>The Difference between a Procedure and Its Name
<LI>The Association List of Functions
<LI>Domain Checking
<LI>Intentionally Confusing a Function with Its Name
<LI>More on Higher-Order Functions
<LI>More Robustness
<LI>Complete Program Listing
</UL>

<H3>22. Files</H3>
<UL>
<LI>Ports
<LI>Writing Files for People to Read
<LI>Using a File as a Database
<LI>Transforming the Lines of a File
<LI>Justifying Text
<LI>Preserving Spacing of Text from Files
<LI>Merging Two Files
<LI>Writing Files for Scheme to Read
<LI>Pitfalls
</UL>

<H3>23. Vectors</H3>
<UL>
<LI>The Indy 500
<LI>Vectors
<LI>Using Vectors in Programs
<LI>Non-Functional Procedures and State
<LI>Shuffling a Deck
<LI>More Vector Tools
<LI>The Vector Pattern of Recursion
<LI>Vectors versus Lists
<LI>State, Sequence, and Effects
<LI>Pitfalls
</UL>

<H3>24. Example: A Spreadsheet Program</H3>
<UL>
<LI>Limitations of Our Spreadsheet
<LI>Spreadsheet Commands
<LI>Moving the Selection
<LI>Putting Values in Cells
<LI>Formulas
<LI>Displaying Formula Values
<LI>Loading Spreadsheet Commands from a File
<LI>Application Programs and Abstraction
</UL>

<H3>25. Implementing the Spreadsheet Program</H3>
<UL>
<LI>Cells, Cell Names, and Cell IDs
<LI>The Command Processor
<LI>Cell Selection Commands
<LI>The <CODE>Load</CODE> Command
<LI>The <CODE>Put</CODE> Command
<LI>The Formula Translator
<LI>The Dependency Manager
<LI>The Expression Evaluator
<LI>The Screen Printer
<LI>The Cell Manager
<LI>Complete Program Listing
</UL>

<H3>Project: A Database Program</H3>
<UL>
<LI>A Sample Session with Our Database
<LI>How Databases Are Stored Internally
<LI>The Current Database
<LI>Implementing the Database Program Commands
<LI>Additions to the Program
<LI>Extra Work for Hotshots
</UL>

<A HREF="part7.html"><H2>Part VII. Conclusion: Computer Science</H2></A>

<H3>26. What's Next?</H3>
<UL>
<LI>The Best Computer Science Book
<LI>Beyond <CITE>SICP</CITE>
<LI>Standard Scheme
<LI>Last Words
</UL>

<H2>Appendices</H2>

<H3>A. Running Scheme</H3>
<UL>
<LI>The Program Development Cycle
<LI>Integrated Editing
<LI>Getting Our Programs
<LI>Tuning Our Programs for Your System
<LI>Loading Our Programs
<LI>Versions of Scheme
<LI>Scheme Standards
</UL>

<H3>B. Common Lisp</H3>
<UL>
<LI>Why Common Lisp Exists
<LI>Defining Procedures and Variables
<LI>The Naming Convention for Predicates
<LI>No Words or Sentences
<LI>True and False
<LI>Files
<LI>Arrays
<LI>Equivalents to Scheme Primitives
<LI>A Separate Name Space for Procedures
<LI><CODE>Lambda</CODE>
<LI>More about <CODE>Function</CODE>
<LI>Writing Higher-Order Procedures
</UL>

<H3>C. Scheme Initialization File</H3>

<H3>D. GNU General Public License</H3>
<H3>Credits</H3>
<H3>Alphabetical Table of Scheme Primitives</H3>
<H3>Glossary</H3>
<H3>Index of Defined Procedures</H3>
<H3>General Index</H3>

<P>
<A HREF="http://mitpress.mit.edu/0262082810">MIT
Press web page for <CITE>Simply Scheme</CITE></A>

<P>
<ADDRESS>
<A HREF="index.html">Brian Harvey</A>, 
<CODE>bh@cs.berkeley.edu</CODE>
</ADDRESS>
<BR>
<ADDRESS>
<A HREF="http://www.cnmat.berkeley.edu/~matt">Matthew Wright</A>,
<CODE>matt@cnmat.berkeley.edu</CODE>
</ADDRESS>
</BODY>
</HTML>