Skip to content
This repository was archived by the owner on Sep 30, 2021. It is now read-only.

Commit c14250a

Browse files
committed
Merge branch 'release/v1.0'
2 parents cac082c + 154192c commit c14250a

21 files changed

+315
-1016
lines changed

Diff for: .gitignore

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
# C/C++ ignores
2+
3+
# Prerequisites
4+
*.d
5+
16
# Object files
27
*.o
8+
*.ko
9+
*.obj
10+
*.elf
11+
12+
# Precompiled Headers
13+
*.gch
14+
*.pch
315

416
# Libraries
517
*.lib
618
*.a
7-
!lib/libcmockery_la-cmockery.o
19+
*.la
20+
*.lo
821

922
# Shared objects (inc. Windows DLLs)
1023
*.dll
@@ -16,3 +29,16 @@
1629
*.exe
1730
*.out
1831
*.app
32+
*.i*86
33+
*.x86_64
34+
*.hex
35+
36+
# Debug files
37+
*.dSYM/
38+
*.su
39+
40+
############
41+
42+
# Emacs
43+
44+
*~

Diff for: Credits.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Credits
2+
3+
People that contributed to this write-up before the project was moved
4+
to Github included Nic McPhee, Vincent Borchardt, and KK Lamberty.

Diff for: README.md

+117-162
Large diffs are not rendered by default.

Diff for: Tips_and_suggestions.md

+11-56
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1+
# Tips and suggestions
2+
13
Some general comments, tip, and suggestions for this lab:
24

3-
# Correctness
5+
## Correctness
46

57
The one non-subtle issue that came up in several places was that
68
people simply failed to free temporary memory they'd allocated.
79
`valgrind` is very good about catching these kinds of problems, so
810
there's really no reason for not finding and fixing those problems.
911

10-
There was a strong inverse correlation between length and
11-
correctness. The broken `array_merge` submissions were almost all
12-
well onto the second page, where the correct ones almost all fit
13-
nicely on a single page. This may be partly due to the increased
14-
tendency of broken programs to have print code and commented code,
15-
but probably more generally reflects a lack of clarity.
16-
1712
Several people got lost in their array indices, and some remained
1813
lost there throughout. This is a nice example of a problem where
1914
loop invariants could be really useful in helping you stay clear
@@ -37,30 +32,11 @@ Several groups had off-by-one errors where they weren't allocating
3732
you need to make sure that you allocate *N+1* characters so there's
3833
room for the null terminator at the end. This can be tricky to find
3934
because the tests actually pass even if you make this make this
40-
mistake. (To be honest, I'm not entirely sure *why* the tests pass.
41-
I assume that somehow we're getting lucky and getting a 0 byte at
42-
the end of our strings. I suspect that if we dug around some we
43-
could come up with a test that would fail, but I haven't been able
44-
to do so yet.) `valgrind` picks it up, though, and complains about
35+
mistake. `valgrind` notices this problem and complains about
4536
illegal reads and writes when we try to access the memory location
4637
where the null terminator would need to be, but which we never
4738
allocated space for.
4839

49-
A number of groups had a subtle mistake where they
50-
51-
1. Dynamically allocated an array that was potentially empty: `int *a = calloc(n, sizeof(int));`.
52-
1. Copied some data into that array using a loop that (correctly) did nothing if *n=0*.
53-
1. Accessed the first item in the array, which might not actually be there, e.g., `int i = a[0];`.
54-
1. Protected the remainder of the code (through an `if` or loop with appropriate bounds) so that the value taken from the array was never *used* if n=0.
55-
56-
This is broken since the line `int i = a[0];` is accessing a
57-
memory location that hasn't been allocated to your program. It's
58-
probably a legal memory address, though, so it's unlikely to actually
59-
*fail*. And since the subsequent guards ensure that you never actually
60-
use the (probably random) value that you got back, there probably aren't
61-
any tests that will actually catch the mistake. Luckily `valgrind` catches
62-
it, complaining about an illegal read.
63-
6440
# Style and clarity: The big issues
6541

6642
Please use decent variable names! C is a challenging language and
@@ -75,20 +51,9 @@ Initialize variables where you use them. Several people declared
7551
between. (Breaking things up into smaller functions would do much to
7652
lessen this problem - see below.)
7753

78-
Use functions to break things up! Many of the submissions have
79-
`array_merge` as a single function that went on for over a page. Several people have a
80-
second function that looks for duplicates, which is nice, but that
81-
was about it by way of modularity for most folks. Remember the bit
82-
about C being a challenging language, and not making it worse?
83-
Applies here, too. A nice rule of thumb (for any language) is that a
84-
function should have at most one loop. Almost everyone had at least
85-
three loops in their `array_merge` function, with several people
86-
getting as high as 6. I'd have a look at that if I were you.
87-
88-
On a related note, *many* people have their vowel check in
89-
`disemvowel` as a huge long chain of `||` statements. Pull that
90-
stuff out into a named function, *especially* if you end up
91-
repeating it!
54+
Use functions to break things up! In the past, for example, many people
55+
have had their vowel check in `disemvowel` as one huge long chain of `||` statements. Pull that stuff out into a named function, *especially* if
56+
you end up repeating it!
9257

9358
# Style and clarity: Odds and ends
9459

@@ -107,20 +72,10 @@ Don't `#include` `.c` files; you want to compile `.c` files
10772
linker pulls them all together into a working executable.
10873

10974
Pay attention to warnings, and ask if you don't understand what it's
110-
saying. There were several cases where the compiler warnings pointed
111-
right to the problem.
75+
saying. It's not uncommon for people to ask questions when the
76+
compiler warnings are pointing right to the problem.
11277

113-
Use C's `bool` type (with values `true` and `false`) instead of `int`s
78+
As appropriate, use C's `bool` type (with values `true` and `false`)
79+
instead of `int`s
11480
with the values 0 and 1. Booleans are a lot more readable and less error
11581
prone.
116-
117-
# Algorithmic issues
118-
119-
Several people did a variant of linear search to see if an item was
120-
duplicated. Use the fact that your array is sorted (or go ahead and
121-
sort it if it isn't) to simplify this (and speed it up, but the
122-
simplicity is arguably the bigger issue).
123-
124-
---
125-
126-
These notes were started by Vincent Borchardt, 16 Aug 2012

Diff for: array_merge/array_merge.h

-10
This file was deleted.

Diff for: array_merge/array_merge_test.c

-129
This file was deleted.

Diff for: disemvowel/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# We don't want to commit the generated binaries.
2+
main
3+
disemvowel_test

Diff for: disemvowel/disemvowel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#include "disemvowel.h"
44

55
char* disemvowel(char* str) {
6-
return "";
6+
return (char*) "";
77
}

Diff for: disemvowel/disemvowel_test.c

-60
This file was deleted.

0 commit comments

Comments
 (0)