text:
C Programming/Program flow control

Very few programs follow exactly one control path and have each instruction stated explicitly. In order to program effectively, it is necessary to understand how one can alter the steps taken by a program due to user input or other conditions, how some steps can be executed many times with few lines of code, and how programs can appear to demonstrate a rudimentary grasp of logic. C constructs known as conditionals and loops grant this power.

From this point forward, it is necessary to understand what is usually meant by the word block. A block is a group of code statements that are associated and intended to be executed as a unit. In C, the beginning of a block of code is denoted with { (left curly), and the end of a block is denoted with }. It is not necessary to place a semicolon after the end of a block. Blocks can be empty, as in {}. Blocks can also be nested; i.e. there can be blocks of code within larger blocks.

Conditionals
There is likely no meaningful program written in which a computer does not demonstrate basic decision-making skills. It can actually be argued that there is no meaningful human activity in which some sort of decision-making, instinctual or otherwise, does not take place. For example, when driving a car and approaching a traffic light, one does not think, "I will continue driving through the intersection." Rather, one thinks, "I will stop if the light is red, go if the light is green, and if yellow go only if I am traveling at a certain speed a certain distance from the intersection." These kinds of processes can be simulated in C using conditionals.

A conditional is a statement that instructs the computer to execute a certain block of code or alter certain data only if a specific condition has been met. The most common conditional is the If-Else statement, with conditional expressions and Switch-Case statements typically used as more shorthanded methods.

Before one can understand conditional statements, it is first necessary to understand how C expresses logical relations. C treats logic as being arithmetic. The value 0 (zero) represents false, and all other values represent true. If you chose some particular value to represent true and then compare values against it, sooner or later your code will fail when your assumed value (often 1) turns out to be incorrect. Code written by people uncomfortable with the C language can often be identified by the usage of #define to make a "TRUE" value.

Because logic is arithmetic in C, arithmetic operators and logical operators are one and the same. Nevertheless, there are a number of operators that are typically associated with logic:

Relational and Equivalence Expressions:

 * a < b: 1 if a is less than b, 0 otherwise.
 * a > b: 1 if a is greater than b, 0 otherwise.
 * a <= b: 1 if a is less than or equal to b, 0 otherwise.
 * a >= b: 1 if a is greater than or equal to b, 0 otherwise.
 * a == b: 1 if a is equal to b, 0 otherwise.
 * a != b: 1 if a is not equal to b, 0 otherwise

New programmers should take special note of the fact that the "equal to" operator is ==, not =. This is the cause of numerous coding mistakes and is often a difficult-to-find bug, as the expression  sets   equal to   and subsequently evaluates to  ; but the expression , which is usually intended, checks if   is equal to. It needs to be pointed out that, if you confuse = with ==, your mistake will often not be brought to your attention by the compiler. A statement such as  is considered perfectly valid by the language, but will always assign 20 to   and evaluate as true. A simple technique to avoid this kind of bug (in many, not all cases) is to put the constant first. This will cause the compiler to issue an error, if == got misspelled with =.

Note that C does not have a dedicated boolean type as many other languages do. 0 means false and anything else true. So the following are equivalent:

and

Often  and   are used to work around the lack of a boolean type. This is bad practice, since it makes assumptions that do not hold. It is a better idea to indicate what you are actually expecting as a result from a function call, as there are many different ways of indicating error conditions, depending on the situation.

Here,  returns the index where the substring foo is found and -1 if it was not found. Note: this would always fail with the  definition mentioned in the previous paragraph. It would also not produce the expected results if we omitted the.

One other thing to note is that the relational expressions do not evaluate as they would in mathematical texts. That is, an expression  does not evaluate as you probably think it might. Mathematically, this would test whether or not value is between myMin and myMax. But in C, what happens is that value is first compared with myMin. This produces either a 0 or a 1. It is this value that is compared against myMax. Example:

Because value is greater than 0, the first comparison produces a value of 1. Now 1 is compared to be less than 10, which is true, so the statements in the if are executed. This probably is not what the programmer expected. The appropriate code would be:

Logical Expressions

 * a || b: when EITHER a or b is true (or both), the result is 1, otherwise the result is 0.
 * a && b: when BOTH a and b are true, the result is 1, otherwise the result is 0.
 * !a: when a is true, the result is 0; when a is 0, the result is 1.

Here's an example of a larger logical expression. In the statement: e = ((a && b) || (c > d)); e is set equal to 1 if a and b are non-zero, or if c is greater than d. In all other cases, e is set to 0.

C uses short circuit evaluation of logical expressions. That is to say, once it is able to determine the truth of a logical expression, it does no further evaluation. This is often useful as in the following:

int myArray[12]; .... if (i < 12 && myArray[i] > 3) { ....

In the snippet of code, the comparison of i with 12 is done first. If it evaluates to 0 (false), i would be out of bounds as an index to myArray. In this case, the program never attempts to access myArray[i] since the truth of the expression is known to be false. Hence we need not worry here about trying to access an out-of-bounds array element if it is already known that i is greater than or equal to zero. A similar thing happens with expressions involving the or || operator.

while (doThis || doThat) ...

doThat is never called if doThis returns a non-zero (true) value.

The If-Else statement
If-Else provides a way to instruct the computer to execute a block of code only if certain conditions have been met. The syntax of an If-Else construct is:

The first block of code executes if the condition in parentheses directly after the if evaluates to non-zero (true); otherwise, the second block executes.

The else and following block of code are completely optional. If there is no need to execute code if a condition is not true, leave it out.

Also, keep in mind that an if can directly follow an else statement. While this can occasionally be useful, chaining more than two or three if-elses in this fashion is considered bad programming practice. We can get around this with the Switch-Case construct described later.

Two other general syntax notes need to be made that you will also see in other control constructs: First, note that there is no semicolon after if or else. There could be, but the block (code enclosed in { and }) takes the place of that. Second, if you only intend to execute one statement as a result of an if or else, curly braces are not needed. However, many programmers believe that inserting curly braces anyway in this case is good coding practice.

The following code sets a variable c equal to the greater of two variables a and b, or 0 if a and b are equal.

Consider this question: why can't you just forget about else and write the code like:

There are several answers to this. Most importantly, if your conditionals are not mutually exclusive, two cases could execute instead of only one. If the code was different and the value of a or b changes somehow (e.g.: you reset the lesser of a and b to 0 after the comparison) during one of the blocks? You could end up with multiple if statements being invoked, which is not your intent. Also, evaluating if conditionals takes processor time. If you use else to handle these situations, in the case above assuming (a > b) is non-zero (true), the program is spared the expense of evaluating additional if statements. The bottom line is that it is usually best to insert an else clause for all cases in which a conditional will not evaluate to non-zero (true).

The conditional expression
A conditional expression is a way to set values conditionally in a more shorthand fashion than If-Else. The syntax is:

(/* logical expression goes here */) ? (/* if non-zero (true) */) : (/* if 0 (false) */)

The logical expression is evaluated. If it is non-zero (true), the overall conditional expression evaluates to the expression placed between the ? and :, otherwise, it evaluates to the expression after the :. Therefore, the above example (changing its function slightly such that c is set to b when a and b are equal) becomes:

c = (a > b) ? a : b;

Conditional expressions can sometimes clarify the intent of the code. Nesting the conditional operator should usually be avoided. It's best to use conditional expressions only when the expressions for a and b are simple. Also, contrary to a common beginner belief, conditional expressions do not make for faster code. As tempting as it is to assume that fewer lines of code result in faster execution times, there is no such correlation.

The Switch-Case statement
Say you write a program where the user inputs a number 1-5 (corresponding to student grades, A(represented as 1)-D(4) and F(5)), stores it in a variable grade and the program responds by printing to the screen the associated letter grade. If you implemented this using If-Else, your code would look something like this:

Having a long chain of if-else-if-else-if-else can be a pain, both for the programmer and anyone reading the code. Fortunately, there's a solution: the Switch-Case construct, of which the basic syntax is:

The Switch-Case construct takes a variable, usually an int or an enum, placed after switch, and compares it to the value following the case keyword. If the variable is equal to the value specified after case, the construct "activates", or begins executing the code after the case statement. Once the construct has "activated", there will be no further evaluation of cases.

Switch-Case is syntactically "weird" in that no braces are required for code associated with a case.

Very important: Typically, the last statement for each case is a break statement. This causes program execution to jump to the statement following the closing bracket of the switch statement, which is what one would normally want to happen. However if the break statement is omitted, program execution continues with the first line of the next case, if any. This is called a fall-through. When a programmer desires this action, a comment should be placed at the end of the block of statements indicating the desire to fall through. Otherwise another programmer maintaining the code could consider the omission of the 'break' to be an error, and inadvertently 'correct' the problem. Here's an example:

If a default case is specified, the associated statements are executed if none of the other cases match. A default case is optional. Here's a switch statement that corresponds to the sequence of if - else if statements above.

Back to our example above. Here's what it would look like as Switch-Case:

A set of statements to execute can be grouped with more than one value of the variable as in the following example. (the fall-through comment is not necessary here because the intended behavior is obvious)

Switch-Case constructs are particularly useful when used in conjunction with user defined enum data types. Some compilers are capable of warning about an unhandled enum value, which may be helpful for avoiding bugs.

Loops
Often in computer programming, it is necessary to perform a certain action a certain number of times or until a certain condition is met. It is impractical and tedious to simply type a certain statement or group of statements a large number of times, not to mention that this approach is too inflexible and unintuitive to be counted on to stop when a certain event has happened. As a real-world analogy, someone asks a dishwasher at a restaurant what he did all night. He will respond, "I washed dishes all night long." He is not likely to respond, "I washed a dish, then washed a dish, then washed a dish, then...". The constructs that enable computers to perform certain repetitive tasks are called loops.

While loops
A while loop is the most basic type of loop. It will run as long as the condition is non-zero (true). For example, if you try the following, the program will appear to lock up and you will have to manually close the program down. A situation where the conditions for exiting the loop will never become true is called an infinite loop.

Here is another example of a while loop. It prints out all the powers of two less than 100.

The flow of all loops can also be controlled by break and continue statements. A break statement will immediately exit the enclosing loop. A continue statement will skip the remainder of the block and start at the controlling conditional statement again. For example:

In this example, the computer prints the value of a as usual, and prints a notice that a is not 64 (unless it was skipped by the continue statement).

Similar to If above, braces for the block of code associated with a While loop can be omitted if the code consists of only one statement, for example:

This will merely increase a until a is not less than 100.

When the computer reaches the end of the while loop, it always goes back to the while statement at the top of the loop, where it re-evaluates the controlling condition. If that condition is "true" at that instant -- even if it was temporarily 0 for a few statements inside the loop -- then the computer begins executing the statements inside the loop again; otherwise the computer exits the loop. The computer does not "continuously check" the controlling condition of a while loop during the execution of that loop. It only "peeks" at the controlling condition each time it reaches the  at the top of the loop.

It is very important to note, once the controlling condition of a While loop becomes 0 (false), the loop will not terminate until the block of code is finished and it is time to reevaluate the conditional. If you need to terminate a While loop immediately upon reaching a certain condition, consider using break.

A common idiom is to write:

This executes the code in the while loop 5 times, with i having values that range from 4 down to 0 (inside the loop). Conveniently, these are the values needed to access every item of an array containing 5 elements.

For loops
For loops generally look something like this:

for (initialization; test; increment) { /* code */ }

The initialization statement is executed exactly once - before the first evaluation of the test condition. Typically, it is used to assign an initial value to some variable, although this is not strictly necessary. The initialization statement can also be used to declare and initialize variables used in the loop.

The test expression is evaluated each time before the code in the for loop executes. If this expression evaluates as 0 (false) when it is checked (i.e. if the expression is not true), the loop is not (re)entered and execution continues normally at the code immediately following the FOR-loop. If the expression is non-zero (true), the code within the braces of the loop is executed.

After each iteration of the loop, the increment statement is executed. This often is used to increment the loop index for the loop, the variable initialized in the initialization expression and tested in the test expression. Following this statement execution, control returns to the top of the loop, where the test action occurs. If a continue statement is executed within the for loop, the increment statement would be the next one executed.

Each of these parts of the for statement is optional and may be omitted. Because of the free-form nature of the for statement, some fairly fancy things can be done with it. Often a for loop is used to loop through items in an array, processing each item at a time.

The above for loop initializes each of the 12 elements of myArray. The loop index can start from any value. In the following case it starts from 1.

which will print 1 2 3 4 5 6 7 8 9 10

You will most often use loop indexes that start from 0, since arrays are indexed at zero, but you will sometimes use other values to initialize a loop index as well.

The increment action can do other things, such as decrement. So this kind of loop is common:

which yields 5 4 3 2 1

Here's an example where the test condition is simply a variable. If the variable has a value of 0 or NULL, the loop exits, otherwise the statements in the body of the loop are executed.

A WHILE loop can be used to do the same thing as a FOR loop, however a FOR loop is a more condensed way to perform a set number of repetitions since all of the necessary information is in a one line statement.

A FOR loop can also be given no conditions, for example:

This is called an infinite loop since it will loop forever unless there is a break statement within the statements of the for loop. The empty test condition effectively evaluates as true.

It is also common to use the comma operator in for loops to execute multiple statements.

Special care should be taken when designing or refactoring the conditional part, especially whether using < or <=, whether start and stop should be corrected by 1, and in case of prefix- and postfix-notations. ( On a 100 yards promenade with a tree every 10 yards there are 11 trees. )

Do-While loops
A DO-WHILE loop is a post-check while loop, which means that it checks the condition after each run. As a result, even if the condition is zero (false), it will run at least once. It follows the form of:

Note the terminating semicolon. This is required for correct syntax. Since this is also a type of while loop, break and continue statements within the loop function accordingly. A continue statement causes a jump to the test of the condition and a break statement exits the loop.

It is worth noting that Do-While and While are functionally almost identical, with one important difference: Do-While loops are always guaranteed to execute at least once, but While loops will not execute at all if their condition is 0 (false) on the first evaluation.

One last thing: goto
goto is a very simple and traditional control mechanism. It is a statement used to immediately and unconditionally jump to another line of code. To use goto, you must place a label at a point in your program. A label consists of a name followed by a colon on a line by itself. Then, you can type "goto label;" at the desired point in your program. The code will then continue executing beginning with label. This looks like:

The ability to transfer the flow of control enabled by gotos is so powerful that, in addition to the simple if, all other control constructs can be written using gotos instead. Here, we can let "S" and "T" be any arbitrary statements:

The same statement could be accomplished using two gotos and two labels:

Here, the first goto is conditional on the value of "cond". The second goto is unconditional. We can perform the same translation on a loop:

Which can be written as:

As these cases demonstrate, often the structure of what your program is doing can usually be expressed without using gotos. Undisciplined use of gotos can create unreadable, unmaintainable code when more idiomatic alternatives (such as if-elses, or for loops) can better express your structure. Theoretically, the goto construct does not ever have to be used, but there are cases when it can increase readability, avoid code duplication, or make control variables unnecessary. You should consider first mastering the idiomatic solutions, and use goto only when necessary. Keep in mind that many, if not most, C style guidelines strictly forbid use of goto, with the only common exceptions being the following examples.

One use of goto is to break out of a deeply nested loop. Since break will not work (it can only escape one loop), goto can be used to jump completely outside the loop. Breaking outside of deeply nested loops without the use of the goto is always possible, but often involves the creation and testing of extra variables that may make the resulting code far less readable than it would be with goto. The use of goto makes it easy to undo actions in an orderly fashion, typically to avoid failing to free memory that had been allocated.

Another accepted use is the creation of a state machine. This is a fairly advanced topic though, and not commonly needed.

title: C Programming/Program flow control


text:
C Programming/Procedures and functions

In C programming, all executable code resides within a function. Note that other programming languages may distinguish between a "function", "subroutine", "subprogram", "procedure", or "method" -- in C, these are all functions. Functions are a fundamental feature of any high level programming language and make it possible to tackle large, complicated tasks by breaking tasks into smaller, more manageable pieces of code.

At a lower level, a function is nothing more than a memory address where the instructions associated with a function reside in your computer's memory. In the source code, this memory address is usually given a descriptive name which programmers can use to call the function and execute the instructions that begin at the function's starting address. The instructions associated with a function are frequently referred to as a block of code. After the function's instructions finish executing, the function can return a value and code execution will resume with the instruction that immediately follows the initial call to the function. If this doesn't make immediate sense to you, don't worry. Understanding what is happening inside your computer at the lowest levels can be confusing at first, but will eventually become very intuitive as you develop your C programming skills.

For now, it's enough to know that a function and its associated block of code is often executed (called) several times, from several different places, during a single execution of a program.

As a basic example, suppose you are writing a program that calculates the distance of a given (x,y) point to the x-axis and to the y-axis. You will need to compute the absolute value of the whole numbers x and y. We could write it like this (assuming we don't have a predefined function for absolute value in any library):

The next example illustrates the usage of a function as a procedure. It's a simplistic program that asks students for their grade for three different courses and tells them if they passed a course. Here, we created a function, called  that can be called as many times as we need to. The function saves us from having to write the same set of instructions for each class the student has taken.

Notice that in the program above, there is no outcome value for the 'check' function. It only executes a procedure.

This is precisely what functions are for.

More on functions
It's useful to conceptualize a function like a machine in a factory. On the input side of the machine, you dump in the "raw materials," or the input data, that you want the machine to process. Then the machine goes to work and and spits out a finished product, the "return value," to the output side of the machine which you can collect and use for other purposes.

In C, you must tell the machine exactly what raw materials it is expected to process and what kind of finished product you want the machine to return to you. If you supply the machine with different raw materials than it expects, or if you try to return a product that's different than what you told the machine to produce, the C compiler will throw an error.

Note that a function isn't required to take any inputs. It doesn't have to return anything back to us, either. If we modify the example above to ask the user for their grade inside the  function, there would be no need to pass the grade value into the function. And notice that the  doesn't pass a value back. The function just prints out a message to the screen.

You should be familiar with some basic terminology related to functions:
 * A function, call it f, that uses another function g, is said to call g. For example, f calls g to print the squares of ten numbers. f is referred to as the caller function and g is the callee.
 * The inputs we send to a function are called its arguments. When we declare our function, we describe the parameters that determine what type of arguments are acceptable to pass into the function. We describe these parameters to the compiler inside a set of parentheses next to the function's name.
 * A function g that gives some kind of answer back to f is said to return that answer or value. For example, g returns the sum of its arguments.

Writing functions in C
It's always good to learn by example. Let's write a function that will return the square of a number.

To understand how to write such a function like this, it may help to look at what this function does as a whole. It takes in an int, x, and squares it, storing it in the variable square_of_x. Now this value is returned.

The first int at the beginning of the function declaration is the type of data that the function returns. In this case when we square an integer we get an integer, and we are returning this integer, and so we write int as the return type.

Next is the name of the function. It is good practice to use meaningful and descriptive names for functions you may write. It may help to name the function after what it is written to do. In this case we name the function "square", because that's what it does - it squares a number.

Next is the function's first and only argument, an int, which will be referred to in the function as x. This is the function's input.

In between the braces is the actual guts of the function. It declares an integer variable called square_of_x that will be used to hold the value of the square of x. Note that the variable square_of_x can only be used within this function, and not outside. We'll learn more about this sort of thing later, and we will see that this property is very useful.

We then assign x multiplied by x, or x squared, to the variable square_of_x, which is what this function is all about. Following this is a return statement. We want to return the value of the square of x, so we must say that this function returns the contents of the variable square_of_x.

Our brace to close, and we have finished the declaration.

Written in a more concise manner, this code performs exactly the same function as the above:

Note this should look familiar - you have been writing functions already, in fact - main is a function that is always written.

In general
In general, if we want to declare a function, we write type name(type1 arg1, type2 arg2, ...) {   /* code */ }

We've previously said that a function can take no arguments, or can return nothing, or both. What do we write if we want the function to return nothing? We use C's void keyword. void basically means "nothing" - so if we want to write a function that returns nothing, for example, we write

Notice that there is no return statement in the function above. Since there's none, we write void as the return type. (Actually, one can use the <tt>return</tt> keyword in a procedure to return to the caller before the end of the procedure, but one cannot return a value as if it were a function.)

What about a function that takes no arguments? If we want to do this, we can write for example

Notice this function doesn't take any inputs, but merely returns a number calculated by this function.

Naturally, you can combine both void return and void in arguments together to get a valid function, also.

Recursion
Here's a simple function that does an infinite loop. It prints a line and calls itself, which again prints a line and calls itself again, and this continues until the stack overflows and the program crashes. A function calling itself is called recursion, and normally you will have a conditional that would stop the recursion after a small, finite number of steps.

A simple check can be done like this. Note that ++depth is used so the increment will take place before the value is passed into the function. Alternatively you can increment on a separate line before the recursion call. If you say print_me(3,0); the function will print the line Recursion 3 times.

Recursion is most often used for jobs such as directory tree scans, seeking for the end of a linked list, parsing a tree structure in a database and factorising numbers (and finding primes) among other things.

Static functions
If a function is to be called only from within the file in which it is declared, it is appropriate to declare it as a static function. When a function is declared static, the compiler will know to compile an object file in a way that prevents the function from being called from code in other files. Example:

Using C functions
We can now write functions, but how do we use them? When we write main, we place the function outside the braces that encompass main.

When we want to use that function, say, using our <tt>calculate_number</tt> function above, we can write something like

If a function takes in arguments, we can write something like

If a function doesn't return anything, we can just say

since we don't need a variable to catch its return value.

Functions from the C Standard Library
While the C language doesn't itself contain functions, it is usually linked with the C Standard Library. To use this library, you need to add an #include directive at the top of the C file, which may be one of the following from C89/C90:

The functions available are:

Variable-length argument lists
Functions with variable-length argument lists are functions that can take a varying number of arguments. An example in the C standard library is the <tt>printf</tt> function, which can take any number of arguments depending on how the programmer wants to use it.

C programmers rarely find the need to write new functions with variable-length arguments. If they want to pass a bunch of things to a function, they typically define a structure to hold all those things -- perhaps a linked list, or an array -- and call that function with the data in the arguments.

However, you may occasionally find the need to write a new function that supports a variable-length argument list. To create a function that can accept a variable-length argument list, you must first include the standard library header <tt>stdarg.h</tt>. Next, declare the function as you would normally. Next, add as the last argument an ellipsis ("..."). This indicates to the compiler that a variable list of arguments is to follow. For example, the following function declaration is for a function that returns the average of a list of numbers:

Note that because of the way variable-length arguments work, we must somehow, in the arguments, specify the number of elements in the variable-length part of the arguments. In the <tt>average</tt> function here, it's done through an argument called <tt>n_args.</tt> In the <tt>printf</tt> function, it's done with the format codes that you specify in that first string in the arguments you provide.

Now that the function has been declared as using variable-length arguments, we must next write the code that does the actual work in the function. To access the numbers stored in the variable-length argument list for our <tt>average</tt> function, we must first declare a variable for the list itself:

The <tt>va_list</tt> type is a type declared in the <tt>stdarg.h</tt> header that basically allows you to keep track of your list. To start actually using <tt>myList</tt>, however, we must first assign it a value. After all, simply declaring it by itself wouldn't do anything. To do this, we must call <tt>va_start</tt>, which is actually a macro defined in <tt>stdarg.h.</tt> In the arguments to <tt>va_start</tt>, you must provide the <tt>va_list</tt> variable you plan on using, as well as the name of the last variable appearing before the ellipsis in your function declaration:

Now that <tt>myList</tt> has been prepped for usage, we can finally start accessing the variables stored in it. To do so, use the <tt>va_arg</tt> macro, which pops off the next argument on the list. In the arguments to <tt>va_arg</tt>, provide the <tt>va_list</tt> variable you're using, as well as the primitive data type (e.g. <tt>int</tt>, <tt>char</tt>) that the variable you're accessing should be:

By popping <tt>n_args</tt> integers off of the variable-length argument list, we can manage to find the average of the numbers:

By calling <tt>average (2, 10, 20)</tt>, we get the average of <tt>10</tt> and <tt>20</tt>, which is <tt>15.</tt>

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

title: C Programming/Procedures and functions


text:
C Programming/Basics of compilation

Having covered the basic concepts of C programming, we can now briefly discuss the process of compilation.

Like any programming language, C by itself is completely incomprehensible to a microprocessor. Its purpose is to provide an intuitive way for humans to provide instructions that can be easily converted into machine code that is comprehensible to a microprocessor. The compiler is what translates our human-readable source code into machine code.

To those new to programming, this seems fairly simple. A naive compiler might read in every source file, translate everything into machine code, and write out an executable. That could work, but has two serious problems. First, for a large project, the computer may not have enough memory to read all of the source code at once. Second, if you make a change to a single source file, you would have to recompile the entire application.

To deal with these problems, compilers break the job into steps. For each source file (each  file), the compiler reads the file, reads the files it references via the   directive, and translates them to machine code. The result of this is an "object file". After all the object files are created, a "linker" program collects all of the object files and writes the actual executable program. That way, if you change one source file, only that file needs to be recompiled, after which, the application will need to be re-linked.

Without going into details, it can be beneficial to have a superficial understanding of the compilation process.

Preprocessor
The preprocessor provides the ability for the inclusion of so called header files, macro expansions, conditional compilation and line control. These features can be accessed by inserting the appropriate preprocessor directives into your code. Before compiling the source code, a special program, called the preprocessor, scans the source code for tokens, or special strings, and replaces them with other strings or code according to specific rules. The C preprocessor is not technically part of the C language and is instead a tool offered by your compiler's software.

All preprocessor directives begin with the hash character (#). You can see one preprocessor directive in the Hello world program. Example:

This directive causes the stdio header to be included into your program. Other directives such as  control compiler settings and macros. The result of the preprocessing stage is a text string. You can think of the preprocessor as a non-interactive text editor that modifies your code to prepare it for compilation. The language of preprocessor directives is agnostic to the grammar of C, so the C preprocessor can also be used independently to process other kinds of text files.

Syntax Checking
This step ensures that the code is valid and will sequence into an executable program. Under most compilers, you may get messages or warnings indicating potential issues with your program (such as a conditional statement always being true or false, etc.)

When an error is detected in the program, the compiler will normally report the file name and line that is preventing compilation.

Object Code
The compiler produces a machine code equivalent of the source code that can be linked into the final program. At this point the code itself can't be executed, as it requires linking to do so.

It's important to note after discussing the basics that compilation is a "one way street". That is, compiling a C source file into machine code is easy, but "decompiling" (turning machine code into the C source that creates it) is not. Decompilers for C do exist, but the code they create is hard to understand and only useful for reverse engineering.

Linking
Linking combines the separate object files into one complete program by integrating libraries and the code and producing either an executable program or a library. Linking is performed by a linker program, which is often part of a compiler suite.

Common errors during this stage are either missing or duplicate functions.

Automation
For large C projects, many programmers choose to automate compilation, both in order to reduce user interaction requirements and to speed up the process by recompiling only modified files.

Most Integrated Development Environments (IDE's) have some kind of project management which makes such automation very easy. However, the project management files are often usable only by users of the same integrated development environment, so anyone desiring to modify the project would need to use the same IDE.

On UNIX-like systems, make and Makefiles are often used to accomplish the same. Make is traditional and flexible and is available as one of the standard developer tools on most Unix and GNU distributions.

Makefiles have been extended by the GNU Autotools, composed of Automake and Autoconf for making software compilable, testable, translatable and configurable on many types of machines. Automake and Autoconf are described in detail in their respective manuals.

The Autotools are often perceived to be complicated and various simpler build systems have been developed. Many components of the GNOME project now use the declarative Meson build system which is less flexible, but instead focuses on providing the features most commonly needed from a build system in a simple way. Other popular build systems for programs written in the C language include CMake and Waf.

Once GCC is installed, it can be called with a list of c source files that have been written but not yet compiled. e.g. if the file main.c includes functions described in myfun.h and implemented in myfun_a.c and myfun_b.c, then it is enough to write

gcc  main.c myfun_a.c myfun_b.c

myfun.h is included in main.c, but if it is in a separate header file directory, then that directory can be listed after a "-I " switch.

In larger programs, Makefiles and GNU make program can compile c files into intermediate files ending with suffix .o which can be linked by GCC.

How to compile each object file is usually described in the Makefile with the object file as a label ending with a colon followed by two spaces (tabs often cause problems) followed by a list of other files that are dependencies, e.g. .c files and .o files compiled in another section, and on the next line, the invocation of GCC that is required.

Typing     or    often gives the information needed to on how to use make, as well as GCC.

Although GCC has a lot of option switches, one often used is -g to generate debugging information for gdb to allow gdb to show source code during a step-through of the machine code program. gdb has an 'h' command that shows what it can do, and is usually started with 'gdb a.out' if a.out is the anonymous executable machine code file that was compiled by GCC.

de:C-Programmierung: Kompilierung Programación_en_C/Compilar_un_programa Programmeerimiskeel C/Kompileerimine Programmation C-C%2B%2B/Modularité et compilation C/Compilatore e precompilatore/Compilatore Programar em C/Utilizando um compilador

title: C Programming/Basics of compilation


text:
User talk:Hephaestos~enwikibooks

Hi Hephaestos :) Nice to see Wikibooks has dragged yet another soul from Wikipedia! I'm sure your user page will be as popular here as it is there ;) Have fun! Dysprosia 01:25, 20 Nov 2003 (UTC)

Hephaestos ! Well, this makes for a sunny morning. Welcome ! --Karl Wick

Your account will be renamed
Hello,

The developer team at Wikimedia is making some changes to how accounts work, as part of our on-going efforts to provide new and better tools for our users like cross-wiki notifications. These changes will mean you have the same account name everywhere. This will let us give you new features that will help you edit and discuss better, and allow more flexible user permissions for tools. One of the side-effects of this is that user accounts will now have to be unique across all 900 Wikimedia wikis. See the announcement for more information.

Unfortunately, your account clashes with another account also called Hephaestos. To make sure that both of you can use all Wikimedia projects in future, we have reserved the name Hephaestos~enwikibooks that only you will have. If you like it, you don't have to do anything. If you do not like it, you can pick out a different name.

Your account will still work as before, and you will be credited for all your edits made so far, but you will have to use the new account name when you log in.

Sorry for the inconvenience.

Yours, Keegan Peterzell Community Liaison, Wikimedia Foundation 23:13, 17 March 2015 (UTC)

Renamed
 This account has been renamed as part of single-user login finalisation. If you own this account you can |log in using your previous username and password for more information. If you do not like this account's new name, you can choose your own using this form after logging in: . -- Keegan (WMF) (talk) 05:02, 19 April 2015 (UTC)

title: User talk:Hephaestos~enwikibooks


text:
User:Hephaestos~enwikibooks

Hi all, yes same one. :)

title: User:Hephaestos~enwikibooks


text:
Discrete Mathematics/Finite fields

Introduction
Recall from the previous section that we considered the case where F[x]/ analogous to modular arithmetic but with polynomials, and that when we are looking at numbers modulo n, we have a field iff Zn is a field if n is prime.

Can we say something similar about F[x]/? Indeed, if m(x) is irreducible then F[x]/ is a field.

This section deals with these kinds of fields, known as a finite field.

Definitions
We have the object F[x]/ where this is the set of polynomials in F[x] are divided by the polynomial m(x).

Of the elements in F[x]/ we can easily define addition, subtraction, multiplication, division and so on normally but with a reduction modulo m(x) to get the desired remainder.

We have that F[x]/ is a commutative ring with identity, and if m(x) is irreducible then F[x]/ is a field.

If m(x) has degree n, then
 * $$\mathbf{F}[x] / \langle m(x) \rangle = \{ a_{n-1} x^{n-1} + a_{n-2} x^{n-2} + \dots + a_0 x^0 | a_i \in \mathbf{F} \} $$

If F is Zp (so p is prime) then $$| \mathbf{F}[x] / \langle m(x) \rangle | = p^n$$

Properties
Now remember with complex numbers C, we have "invented" the symbol i to stand for the root of the solution x2+1=0. In fact, we have C=R[x]/.

When we have a general finite field, we can do this also. We write this often as F[x]/=F(α) where α is "the root of" m(x) - we define α to be the root of m(x).

F(α) in fact is the smallest field which contains F and α.

Finite field theorems
We have a number of theorems associated with finite fields.

 * 1) If F is a finite field, |F|=q, then q=pk for some k $$\ge$$ 1 and p prime.
 * 2) There then is a monic irreducible polynomial m(x) with degree k such that F=Zp[x]/=Zp(α) with α a root of m(x) over Zp
 * 3) There is an element γ∈F such that the order (the least element n such that γn=1) of γ is q-1, so γ is primitive in F, and we can generate elements of F (not zero) from powers of γ, i.e. F={0, γ0=1, γ1, ..., γq-2, γq-1=1}
 * 4) F is a vector space with dimension k over Zp. It has basis {1, α, α2,...,αn-1} where n is the degree of m(x), so we have F={an-1αn-1+...+a0α0|ai∈F}
 * 5) If a∈F, a+...+a p times (pa) is 0.
 * 6) If m2(x) is any other irreducible polynomial of degree k over Zp then F is isomorphic (meaning basically equal to, except for a change in symbols) to Zp/ - so all ways of writing this field are basically the same. So there is essentially one field of size q=pk and we denote it GF(pk) (GF meaning Galois Field).

Some examples
Let's look at a few examples that go through these ideas.

The complex numbers
Complex numbers, briefly, are numbers in the form
 * $$ a + bi$$

where i is the solution to the equation x2+1=0

These numbers in fact form a field, however it is not a finite field.

Take m(x)=x2+1, with the field F being R. Then we can form the complex numbers as F/. Now F/ = { a+bx | a, b ∈ R} because the remainders must be of degree less than m(x) - which is 2.

So then (a+bx)(c+dx)=ac+bdx2+(ad+bc)x.

But remember that we are working in F/. So x2 modulo x2+1, can be written as (x2+1)-1=-1, and substituting -1 above yields a rather familiar expression.

If we let the symbol i to be the "root of x2+1", then i2+1=0 and i2=-1. The rest of the field axioms follow from here. We can then say the complex numbers C=R/=R(i).

The Zp case
We can still do this for some field in general. Let's take Z3 for example, and pick m(x)=x2+x+2. m(x) is irreducible - m(0)=2, m(1)=4=1, m(2)=4+2+2=8=2.

So Z3/ is a finite field. Assume α is a root of m(x). Then Z3(α) = { a+bα|a, b ∈ Z3}. Since Z3/<x2+x+2> is finite, we can list out all its elements. We have the constant terms, then the α terms, then the α+constant terms, and so on. We have {0, 1, 2, α, α+1, α+2, 2α, 2α+1, 2α+2}.

Now we have α2+α+2=0, then
 * α2=-α-2
 * α2=2α-2=2α+1

(Recall the coefficients are in Z3! We are working in Z3/<m(x)>)

We can verify multiplication works mod m(x) - for example
 * (1+2α)(2+α) = 2 + α+4α+2α2

Reducing coefficients normally mod 3 we get
 * (1+2α)(2+α) = 2 + 2α + 2α2

Now using the formula above for α2
 * (1+2α)(2+α)
 * = 2 + 2α + 2(2α+1)
 * = 2 + 2α+4α+2
 * = 2 + 6α+2
 * = 2 + 2 = 4 = 1

Verify for yourself that multiplication and other operations work too.

Primitive elements
Recall from ../Modular arithmetic/ that the order of a number a modulo n, in a field, is the least power such that ak-1=1 in Zn, with k the size of this field. Since the order is defined over a field, this leads us to consider whether we have primitive elements in F[x]/<m(x)> - which we do. If we have F(α), just like in Zn, α is primitive iff the order of α is q-1 where q is the number of elements in F[x]/<m(x)>.

Let's take Z2/<x2+x+1>. Is α (root of x2+x+1) primitive?

First, if α is a root of x2+x+1,
 * α2+α+1=0
 * α2=-α-1=α+1

Now, let us calculate powers of α
 * 1, α
 * α2=α+1
 * α3=α(α2)=α(α+1)=α2+α=(α+1)+α=1

Recall that the size of this field is 4 (the n in Zn, in this case, 2, raised to the power of the degree of the polynomial, in this case 2). Now we have α3=α4-1=1, and α is primitive.

We generally want to look at powers of α in F(α), to see whether they are primitive, since we already know about the orders of the constants in F(α) - which we've looked at in ../Modular arithmetic/.

title: Discrete Mathematics/Finite fields


text:
User:Zabek

Hi.

Brief personal introduction: I am involved in academia, education, and community work.

What brings me here?

I am am extremely interested in the idea of creating a virtual home for open-source annotated texts, a home where readers could create their own commentaries, introductions, critical apparatus, or any other aids for reading and study that might be interesting and helpful.

I strongly feel that such a project should be a separate project from Wikibooks. There is a fundamental difference between creating a school textbook, where the text is primarily a means for presenting the topic, versus a primary text where the text itself is at the center of attention.

But meanwhile the annotated texts are here, and I'd be happy to help contribute what I can to them.

(By the way, yes, I have read the discussion about "Project Sourceberg.")

title: User:Zabek


text:
User talk:Noldoaran~enwikibooks

Welcome Noldoaran, I hope you enjoy yourself here. Thanks in advance for any contributions. Maybe you will have a bit of extra time what with the strike and all ;-) --Karl Wick

Image:Globe.png
I love the picture you created. May I use it as part of a logo for Wikiversity? I consider your rendering to be the best choice, but if you don't feel comfortable having it used in a Wikimedia copyrighted logo, I will trade it for a different globe. If you are willing to give this work to Wikimedia, do you have a bigger bitmap or a vector version? --Zephram Stark 17:40, 26 March 2006 (UTC)

Your account will be renamed
Hello,

The developer team at Wikimedia is making some changes to how accounts work, as part of our on-going efforts to provide new and better tools for our users like cross-wiki notifications. These changes will mean you have the same account name everywhere. This will let us give you new features that will help you edit and discuss better, and allow more flexible user permissions for tools. One of the side-effects of this is that user accounts will now have to be unique across all 900 Wikimedia wikis. See the announcement for more information.

Unfortunately, your account clashes with another account also called Noldoaran. To make sure that both of you can use all Wikimedia projects in future, we have reserved the name Noldoaran~enwikibooks that only you will have. If you like it, you don't have to do anything. If you do not like it, you can pick out a different name.

Your account will still work as before, and you will be credited for all your edits made so far, but you will have to use the new account name when you log in.

Sorry for the inconvenience.

Yours, Keegan Peterzell Community Liaison, Wikimedia Foundation 23:33, 17 March 2015 (UTC)

Renamed
 This account has been renamed as part of single-user login finalisation. If you own this account you can |log in using your previous username and password for more information. If you do not like this account's new name, you can choose your own using this form after logging in: . -- Keegan (WMF) (talk) 05:18, 19 April 2015 (UTC)

title: User talk:Noldoaran~enwikibooks


text:
General Biology/Getting Started/Introduction

The word biology means, "the science of life", from the Greek  bios, life, and  logos, word or knowledge. Therefore, Biology is the science of Living Things. That is why Biology is sometimes known as Life Science.

The science has been divided into many subdisciplines, such as botany, bacteriology, anatomy, zoology, histology, mycology, embryology, parasitology, genetics, molecular biology, systematics, immunology, microbiology, physiology, cell biology, cytology, ecology, and virology. Other branches of science include or are comprised in part of biology studies, including paleontology, taxonomy, evolution, phycology, helimentology, protozoology, entomology, biochemistry, biophysics, biomathematics, bio engineering, bio climatology and anthropology.

Characteristics of life
Not all scientists agree on the definition of just what makes up life. Various characteristics describe most living things. However, with most of the characteristics listed below we can think of one or more examples that would seem to break the rule, with something nonliving being classified as living or something living classified as nonliving. Therefore we are careful not to be too dogmatic in our attempt to explain which things are living or nonliving.

 * Living things are composed of matter structured in an orderly way where simple molecules are ordered together into much larger macromolecules.

An easy way to remember this is GRIMNERD C All organisms; - Grow, Respire, Interact, Move, Need Nutrients, Excrete (Waste), Reproduce,Death, Cells (Made of)

 * Living things are sensitive, meaning they are able to  respond to stimuli.
 * Living things are able to grow, develop, and reproduce.
 * Living things are able to adapt over time by the process of natural selection.
 * All known living things use the hereditary molecule, DNA.
 * Internal functions are coordinated and regulated so that the internal environment of a living thing is relatively constant, referred to as homeostasis.

Living things are organized in the microscopic level from atoms up to cells. Atoms are arranged into molecules, then into macromolecules, which make up organelles, which work together to form cells. Beyond this, cells are organized in higher levels to form entire multicellular organisms. Cells together form tissues, which make up organs, which are part of organ systems, which work together to form an entire organism. Of course, beyond this, organisms form populations which make up parts of an ecosystem. All of the Earth's ecosystems together form the diverse environment that is the earth.

Example:-

sub atoms, atoms, molecules, cells, tissues, organs, organ systems, organisms, population, community, eco systems, biosphere

Emergent property is viewed in the biological organization of life, ranging from the subatomic level to the entire biosphere. Emergent properties are not unique to life, but biological systems are far more complex, making the emergent properties of life difficult to study.

Systems biology is a biology-based inter-disciplinary field of study that focuses on complex interactions within biological systems, using a holistic approach.

Biologists study properties of life, with reductionist approach and holistic approach.

Nature of science
Science is a methodology for learning about the world. It involves the application of knowledge.

The scientific method deals with systematic investigation, reproducible results, the formation and testing of hypotheses, and reasoning.

Reasoning can be broken down into two categories, induction (specific data is used to develop a generalized observation or conclusion) and deduction (general information leads to specific conclusion). Most reasoning in science is done through induction.

Science as we now know it arose as a discipline in the 17th century.

Scientific method
The scientific method is not a step by step, linear process. It is an intuitive process, a methodology for learning about the world through the application of knowledge. Scientists must be able to have an "imaginative preconception" of what the truth is. Scientists will often observe and then hypothesize the reason why a phenomenon occurred. They use all of their knowledge and a bit of imagination, all in an attempt to uncover something that might be true. A typical scientific investigation might go like so:

 * You observe that a room appears dark, and you ponder why the room is dark. In an attempt to find explanations to this curiosity, your mind unravels several different hypotheses.  One hypothesis might state that the lights are turned off.  Another hunch might be that the room's lightbulb has burnt out.  Worst yet, you could be going blind.  To discover the truth, you experiment.  You feel your way around the room and find a light switch and turn it on.  No light.  You repeat the experiment, flicking the switch back and forth.  Still nothing.  That means your initial hypothesis, the room is dark because the lights are off, has been rejected.  You devise more experiments to test your hypotheses, utilizing a flashlight to prove that you are indeed not blind.  In order to accept your last remaining hypothesis as the truth,  you could predict that changing the light bulb will fix the problem.  If all your predictions succeed, the original hypothesis is valid and is accepted.  In some cases, however, your predictions will not occur, in which you'll have to start over.  Perhaps the power is off.

Scientists first make observations that raise a particular question. In order to explain the observed phenomenon, they develop a number of possible explanations, or hypotheses. This is the inductive part of science, observing and constructing plausible arguments for why an event occurred. Experiments are then used to eliminate one or more of the possible hypotheses until one hypothesis remains. Using deduction, scientists use the principles of their hypothesis to make predictions, and then test to make sure that their predictions are confirmed. After many trials (repeatability) and all predictions have been confirmed, the hypothesis then may become a theory.

Quick Definitions

 * Observation - Quantitative and qualitative measurements of the world.
 * Inference - Deriving new knowledge based upon old knowledge.
 * Hypotheses - A suggested explanation.
 * Rejected Hypothesis - An explanation that has been ruled out through experimentation.
 * Accepted Hypothesis - An explanation that has not been ruled out through excessive experimentation and makes verifiable predictions that are true.
 * Experiment - A test that is used to rule out a hypothesis or validate something already known.
 * Scientific Method - The process of scientific investigation.
 * Theory - A widely accepted hypothesis that stands the test of time. Often tested, and usually never rejected.

The scientific method is based primarily on the testing of hypotheses by experimentation. This involves a control, or subject that does not undergo the process in question. A scientist will also seek to limit variables to one or another very small number, single or minimum number of variables. The procedure is to form a hypothesis or prediction about what you believe or expect to see and then do everything you can to violate that, or falsify the hypotheses. Although this may seem unintuitive, the process serves to establish more firmly what is and what is not true.

A founding principle in science is a lack of absolute truth: the accepted explanation is the most likely and is the basis for further hypotheses as well as for falsification. All knowledge has its relative uncertainty.

Theories are hypotheses which have withstood repeated attempts at falsification. Common theories include evolution by natural selection and the idea that all organisms consist of cells. The scientific community asserts that much more evidence supports these two ideas than contradicts them.

Charles Darwin

Charles Darwin is most remembered today for his contribution of the theory of evolution through natural selection.

The seeds of this theory were planted in Darwin's mind through observations made on a five-year voyage through the New World on a ship called the Beagle. There, he studied fossils and the geological record, geographic distribution of organisms, the uniqueness and relatedness of island life forms, and the affinity of island forms to mainland forms.

Upon his return to England, Darwin pondered over his observations and concluded that evolution must occur through natural selection. He declined, however, to publish his work because of its controversial nature. However, when another scientist, Wallace, reached similar conclusions, Darwin was convinced to publish his observations in 1859. His hypothesis revolutionized biology and has yet to be falsified by empirical data collected by mainstream scientists.

After Darwin
Since Darwin's day, scientists have amassed a more complete fossil record, including microorganisms and chemical fossils. These fossils have supported and added subtleties to Darwin's theories. However, the age of the Earth is now held to be much older than Darwin thought. Researchers have also uncovered some of the preliminary mysteries of the mechanism of heredity as carried out through genetics and DNA, areas unknown to Darwin. Another growing area is comparative anatomy including homology and analogy.

Today we can see a bit of evolutionary history in the development  of embryos, as certain (although not all) aspects of development recapitulate evolutionary history.

The molecular biology study of slowly mutating genes reveal considerable evolutionary history consistent with fossil and anatomical record.

Challenges to Darwin

Darwin and his theories have been challenged many times in the last 150 years. The challenges have been primarily religious based on a perceived conflict with the preconceived notion of creationism. Many of those who challenge Darwin have been adherents to the young earth hypothesis that says that the Earth is only some 6000 years old and that all species were individually created by a god. Some of the proponents of these theories have suggested that chemical and physical laws that exist today were different or nonexistent in earlier ages. However, for the most part, these theories are either not scientifically testable and fall outside the area of attention of the field of biology, or have been disproved by one or more fields of science.


text:
User:Zhuo Jia Dai

Hi, my name is Zhuo Jia Dai. I am a maths grad from the University of Sydney. I like maths, although I'm not terribly good at it. My other interests include Go (board game), films, football (soccer) and, diminishingly, video games.

I love political satire and "Yes Minister/Yes Prime minister" are my favourite comedy series of all time. I also like the Chaser boys.

I mainly edit High School Mathematics Extensions.

Below is a modified version of my honours thesis. I intend to continue to improve it and eventually turn it into a wikibook. Please contact me about any suggestions/corrections you may have.

Thesis -- Algebraic Geometric Coding Theory (PDF)

title: User:Zhuo Jia Dai


text:
Puzzles/How do you ... ?/Ten Apples and a Basket

Puzzles | How do you... ? | Ten Apples and A Basket

Ten Apples and A Basket puzzle

You have a basket containing ten apples. You have ten friends, who each desire an apple. You give each of your friends one apple.

After ten minutes, each of your friends has one apple each. Yet there is one remaining apple in the basket.

How is this possible?

Solution


text:
Puzzles/How do you ... ?/Ten Apples and a Basket/Solution

< Back to Problem

Solutions:

 * To your first nine friends, you give them an apple each. To your tenth friend, you hand her the basket containing the apple. She has an apple, but she also has the basket containing the apple.

 * You have ten apples in a basket. You have an eleventh apple in your hand.  You give out the one in your hand and nine of your ten from the basket, leaving one in the basket for you.

//Solutions below are only humorous and not Logical //

 * Since it doesn't say there are only(Do in the real world we always use only? Surely we mean it without saying else every sentence of us will include "only". Consider "My name is only Ramjane".) ten apples in the basket, it's possible the basket could start out with eleven apples in it. Then when you give out ten apples to your ten friends, you still have one apple in the basket.

 * You discover a horrible secret about your friend Brian, end your friendship and put his apple back in the basket
 * Alternately, end Brian, and take the apple back.

 * The basket is lying under an apple tree. At the right moment you shake the tree, catching a falling apple.

 * Ask Brian to wait a minute for his apple. Give the first apple to the second friend, the second to the third, the third to the fourth, the fourth to the fifth, the fifth to the sixth, the sixth to the seventh, the seventh to the eighth, the eighth to the ninth and the ninth apple to Brian, the tenth man, leaving one remaining apple in the basket.

 * You consider yourself as one of the friends, and so you still have the basket with an apple.

 * You went back to the store and bought another apple.

 * Two of your apples got frisky in the basket and had little applets

 * The tenth friend was a magician so he created the eleventh apple.

 * You are a kid and your tenth friend is an imaginary one.


text:
General Biology/Getting Started/Matter

Matter
Matter is defined as anything that has mass (an amount of matter in an object) and occupies space (which is measured as volume).
 * Particles, from smallest to largest and amal is the greatest
 * Subatomic particles
 * Electrons
 * Protons
 * Neutrons
 * Atoms
 * Molecules
 * Macromolecules
 * Origin of matter
 * Big Bang, about 13.7 billion years ago
 * Hydrogen, helium
 * Heavier elements formed in suns, super nova
 * Earth's matter predates formation of sun, 4.5 billion years ago
 * All matter consists of atoms, which are composed of : electrons, protons, neutrons

The atom

 * Example: Hydrogen
 * The simplest element
 * One proton (+)
 * One electron in orbit (-)
 * Built by adding one proton (and one electron) at a time
 * Number of protons determines atomic number and number of electrons
 * Neutrons
 * Neutral charge
 * Contribute mass
 * May decay
 * Oxygen
 * 8 protons (mass)
 * 8 electrons
 * 8 neutrons (mass)

Mass and isotopes

 * Atomic mass
 * Sum of masses of protons and neutrons
 * Measured in daltons or AMU (Atomic Mass Unit)
 * An AMU is 1/12 the mass of Carbon-12
 * proton ~1 AMU or dalton
 * 6.024 x 1023 daltons/gram
 * Atoms with same atomic number belong to same element
 * Isotopes
 * Same atomic number but different atomic mass
 * Some are radioactive
 * Uses of isotopes
 * Radioactive: 3H, 14C, 32P, 35S
 * Tracers in biochemical reactions
 * Detection of molecules in recombinant DNA technology (genetic engineering)
 * Half-life: dating of rocks, fossils
 * Non-radioactive (N, C, O)
 * Diet of organisms (including fossils)
 * Biochemical tracers

Electrons

 * Negative charge
 * Held in orbit about nucleus by attraction to positively charged nucleus
 * Atom may gain or lose electron, altering charge
 * Cation: loses electron, positive charge
 * Na+
 * Anion: gains electron, negative charge
 * Cl-
 * Determine chemical properties of atoms
 * Number
 * Energy level

Chemical bonds

 * Form molecules
 * Enzymes: make, break, rearrange chemical bonds in living systems
 * Ionic
 * Covalent
 * Sharing of one or more pairs of electrons
 * Called single, double, or triple
 * No net charge (as in ionic bonds)
 * No free electrons
 * Give rise to discrete molecules
 * Hydrogen

Chemical reactions

 * Formation and breaking of chemical bonds
 * Shifting arrangement of atoms
 * Reactants -> products
 * Reactions are influenced by:
 * Temperature
 * Concentration of reactants, products
 * Presence of catalysts (enzymes)
 * Oxidation:reduction

Water

 * Essential for life
 * ~75% earth's surface is water
 * Life evolved in water
 * Solvent for many types of solutes
 * High specific heat
 * High polarity
 * Creates a slightly negative Oxygen and a Slightly positive hydrogen
 * allows formation of Hydrogen Bonds

Hydrogen bonding
Water organizes nonpolar molecules Ionization of water: H2O -> H+ + OH- pH
 * A type of polar interaction
 * Critical for:
 * Protein structure
 * Enzymatic reactions
 * Movement of water in plant stems
 * Weak and transient
 * Powerful cumulative effect
 * Solubility of many compounds
 * Cohesion (capillary action)
 * Lower density of ice
 * Formed between molecules other than water
 * Protein structure
 * DNA, RNA structure
 * Nonpolar molecules: no polarity (+/-) charges
 * Hydrophobic: exclude water because they don't form hydrogen bonds with it
 * Consequences:
 * Membranes
 * Protein structure
 * Hydrophilic: polar substances associate with water
 * Forms a Hydrogen ion (H+), hydroxide ion (OH-)
 * Due to spontaneous breakage of covalent bond
 * At 25 °C, 1 liter of water contains 10-7 moles of H+ ions: 10-7 moles/liter
 * A convenient way of indicating H+ concentration
 * pH = -log[H+]
 * For water, pH = -log[10-7] = 7
 * Since for each H+ in pure water, there is one OH-, pH of 7 indicates neutrality
 * Logarithmic scale

Buffer
 * Reservoir for H+
 * Maintains relatively constant pH over buffering range

title: General Biology/Getting Started/Matter


text:
General Biology/Getting Started/Chemical Building Blocks of Life

Building blocks of life
 * Carbon based: organic molecules
 * Carbohydrates: CHO
 * Lipids: CHO, water insoluble
 * Proteins: CHONS, structure/function in cells
 * Nucleic acids: CHONP, hereditary (genetic) information

Carbon

 * Can make 4 covalent bonds
 * Chains
 * Straight
 * Branched
 * Ring
 * Hydrocarbons (C, H): store energy
 * Functional groups
 * Attach to carbon
 * Alter chemical properties
 * Form macromolecules
 * Sapoteton

Carbohydrates

 * Principally CHO (rare N, S and P)
 * 1C:2H:1O ratio
 * Energy rich (many C-H bonds)
 * Monosaccharides (principal: glucose)
 * Simple sugars
 * Principle formula: C6H12O6
 * Form rings in water solution
 * Disaccharides (sucrose, lactose)
 * Polysaccharides (starch, glycogen, cellulose, chitin)

Stereoisomers

 * Bond angles of carbon point to corners of a tetrahedron
 * When 4 different groups are attached to a carbon, it is asymmetric, leading to various types of isomerism
 * Stereoisomers: (D, L)
 * Same chemical properties
 * Different biological properties
 * D sugars, L amino acids

Lipids

 * C-H bonds (nonpolar) instead of C-OH bonds as in carbohydrates
 * High energy
 * Hydrophobic (insoluble in water)
 * Categories
 * Fats: glycerol and three fatty acids
 * Phospholipids: primary component of membranes
 * Prostaglandins: chemical messengers (hormones)
 * Steroids: membrane component; hormones
 * Terpenes: pigments; structure

Fatty acids

 * Hydrocarbon chain
 * Even number of C, 14->20
 * Terminates in carboxyl group
 * Saturated: contain maximum number of hydrogens (all single bonds); maximum energy
 * Unsaturated: one or more double bonds
 * Usually higher melting point
 * Many common oils are polyunsaturated

Proteins

 * Polymer of amino acids
 * 21 different amino acids found in proteins
 * Sequence of amino acids determined by gene
 * Amino acid sequence determines shape of molecule
 * Linked by peptide bond (covalent)
 * Functions
 * regulate chemical reactions and cell processes [enzymes]
 * form bone and muscle; various other tissues
 * facilitate transport across cell membrane [carrier proteins]
 * fight disease [antibodies]
 * Motifs: folding patterns of secondary structure
 * Domains: structural, functional part of protein often independent of another part; often encoded by different exons
 * Shape determines protein's function

Amino acids

 * 21 commonly found in proteins
 * 21st is selenocysteine, not mentioned in text
 * Common structure
 * Amino group: NH2
 * Carboxyl group: COOH
 * R group- 4 different kinds of R groups
 * acidic
 * basic
 * hydrophilic (polar)
 * hydrophobic (nonpolar)
 * Confer individual properties on amino acids
 * List of amino acids

Structure

 * Primary structure: the amino acid sequence
 * Determines higher orders of structure
 * Critical for structure and function of protein
 * Secondary: stabilized by intramolecular hydrogen bonding
 * helix
 * sheet
 * Tertiary: folding, stabilized by ionic bonds (between R groups), hydrogen bonding, van der Waal's forces, hydrophobic interactions
 * Quaternary: _ 2 polypeptides

Function

 * Requires proper folding, cofactors, pH, temperature, etc.
 * Proteins are often modified after synthesis
 * Chemical modification
 * Addition of heme groups (hemoglobin, cytochrome)
 * Denatured proteins can not function properly
 * Proteins are degraded by proteosome as part of constant turnover of cell components

Hereditary (Genetic) information

 * Nucleic acids
 * DNA: deoxyribonucleic acid
 * Hereditary information of all cells
 * Hereditary information for many viruses
 * RNA: ribonucleic acid
 * Hereditary information of certain viruses (HIV)
 * Intermediate in gene expression
 * Composed of nucleotides
 * Ribonucleotides
 * Deoxyribonucleotides

RNA DNA origin

 * Which came first?
 * Paradox: DNA encodes protein necessary for its own replication
 * Discovery of catalytic RNA by Cech and Altman suggested that RNA might have been first self-replicating molecule
 * DNA evolved as more stable type of storage molecule

Proteins: Their building block is amino acids. The bond connecting 2 of the amino acids together are called peptide bonds. One of these bonds makes a monopeptide, two a dipeptide, and any more than that makes a polypeptide.


text:
General Biology/Getting Started/History and Origin of Life

Properties of life

 * 1) Organization: Being structurally composed of one or more cells, which are the basic units of life.
 * 2) * prokaryote: no nucleus
 * 3) * eukaryote: membrane bound nucleus.
 * 4) Sensitivity: respond to stimuli.
 * 5) Energy Processing
 * 6) Growth and Development
 * 7) Reproduction
 * 8) * hereditary mechanisms to make more of self; DNA based.
 * 9) Regulation, including homeostasis.
 * 10) Evolution.

Origin of life: 3 hypotheses
-However, this would imply that some other origin of life was likely because it would have had to happen elsewhere before it could be transported here, and the only difference would be that life did not originate on Earth. -This is often criticized for the improbability of life being produced by a chemical reaction caused by lightning, along with the ability of any produced DNA to be in a sequence that could reproduce a working life model. It is also attacked for religious reasons, as it bypasses things like the idea of a supreme being directly creating humans. It also seems unlikely to some that such huge changes are possible in evolution without evidence of a credible "in-between” stage. Many of the stages of man are disputed due to their somewhat shaky grounds. For example, bones from other animals or species have been mistaken for humanoid while complete skeletons have been put together from a limited number of bones. -This is often attacked for many of the same reasons that religion is attacked, and is often regarded as superstitious and/or unscientific.
 * Extraterrestrial origin (panspermia): meteor, comet borne from elsewhere in universe
 * evidence of amino acids and other organic material in space (but often both D & L forms)
 * questionable bacterial fossils in Martian rock
 * Spontaneous origin on earth: primitive self-replicating macromolecules acted upon by natural selection ((macro)Evolution is one example of this)
 * Special creation: religious explanations (Intelligent Design is one popular example of this.) These explanations contend that life was created by God (or perhaps some other Intelligent Designer).
 * Proponents of Intelligent design suggest that the vast complexity of life could only have been intentionally designed while other creationists cite biblical support.

 * It is debated whether schools should teach one hypothesis over another when discussing the origin of life. However, since they are all accepted hypotheses in some respect, this wikibook will include both of them without favoring one over the other.

The early earth
It is believed that the Earth was formed about 4.5 billion years ago.
 * Heavy bombardment by rubble ceased about 3.8 billion years ago.
 * Reducing atmosphere: much free H
 * also H2O, NH3, CH4
 * little, if any, free O2
 * with numerous H electrons, require little energy to form organic compounds with C
 * Warm oceans, estimated at 49-88 °C
 * Lack of O2 and consequent ozone (O3) meant considerable UV energy

Chemical reactions on early earth
 * UV and other energy sources would promote chemical reactions and formation of organic molecules
 * Testable hypothesis: Miller-Urey experiment
 * simulated early atmospheric conditions
 * found amino acids, sugars, etc., building blocks of life
 * won Nobel prize for work
 * experiment showed prebiotic synthesis of biological molecules was possible

Issues
 * Miller later conceded that the conditions in his experiments were not representative of what is currently thought to be those of early earth
 * He also conceded that science has no answer for how amino acids could self-organize into replicating molecules and cells
 * In the 50 years since Miller-Urey, significant issues and problems for biogenesis have been identified. This is a weak hypothesis at this time.
 * Conclusion: Life exists, we don't know why.

Origin of cells
Cells are very small and decompose quickly after death. As such, fossils of the earliest cells do not exist. Scientists have had to form a variety of theories on how cells (and hence life) was created on Earth.
 * Bubble hypothesis
 * A. Oparin, J.B.S. Haldane, 1930’s
 * Primary abiogenesis: life as consequence of geochemical processes
 * Protobionts: isolated collections of organic material enclosed in hydrophobic bubbles
 * Numerous variants: microspheres, protocells, protobionts, micelles, liposomes, coacervates
 * Other surfaces for evolution of life
 * deep sea thermal vents
 * ice crystals
 * clay surfaces
 * tidal pools

The RNA world?

 * DNA → RNA → polypeptide (protein)
 * Catalytic RNA: ribozyme
 * discovered independently by Tom Cech and Sid Altman (Nobel prize)
 * catalytic properties: hydrolysis, polymerization, peptide bond formation, etc.
 * Self-replicating RNA molecule may have given rise to life
 * consistent with numerous roles for RNA in cells as well as roles for ribonucleotides (ATP)
 * relationship to bubble-like structures is uncertain

The earliest cells
Cyanobacteria
 * Microfossils
 * ~3.5 by
 * resemble bacteria: prokaryotes
 * biochemical residues
 * stromatolites
 * Archaebacteria (more properly Archaea)
 * extremophiles: salt, acid, alkali, heat, methanogens
 * may not represent most ancient life
 * Eubacteria
 * cyanobacteria: photosynthesis
 * atmospheric O2; limestone deposits
 * chloroplasts of eukaryotes

Major steps in evolution of life

 * Prebiotic synthesis of macromolecules
 * Self replication
 * RNA? (primitive metabolism)
 * DNA as hereditary material
 * 1st cells
 * Photosynthesis
 * Aerobic respiration
 * Multicellularity (more than once)


text:
General Biology/Cells/Membranes

Biological membranes
Biological membranes surround cells and serve to keep the insides separated from the outsides. They are formed of phospholipid bilayers, which by definition are a double layer of fatty acid molecules (mostly phospholipids, lipids containing lots of phosphorus).

Proteins serve very important functions in cellular membranes. They are active transports in and out of the cell, acting as gatekeepers. They relay signals in and out of the cell. Proteins are the site of many enzymatic reactions in the cell, and play a role in regulation of cellular processes.

Phospholipid
Phospholipid bilayer
 * basis of biological membranes and cellular organisms
 * contains a charged, hydrophilic (attracted to water) head and two hydrophobic (repelled by water) hydrocarbon tails
 * In presence of water, phospholipids form bilayer
 * maximize hydrogen bonds between water
 * creates barrier to passage of materials
 * fluid mosaic model shows horizontal (common) and "flip-flop" (rare) movement of phospholipids

Fluid mosaic model

 * Current model of membrane
 * Phospholipid bilayer
 * Phospholipids
 * Move freely in lipid layer, but rarely switch layers
 * Different phospholipids in each layer in different organelles
 * Glycolipids
 * Sterols (cholesterol in animals)
 * Transmembrane proteins "float" in fluid lipid bilayer
 * also called intrinsic, integral proteins
 * Exterior (extrinsic, peripheral) proteins

Membrane proteins
Integral membrane proteins
 * Transport channels
 * Enzymes
 * Cell surface receptors
 * Cell surface identity markers
 * Cell adhesion proteins
 * Attachments to cytoskeleton
 * Anchoring to membrane
 * Protein has attached phosphatidylinositol (GPI) linkage, anchors protein in outer layer (no picture)
 * Protein has one or more hydrophobic transmembrane domains
 * -helix
 * -sheet

Channel protein Transport across membranes * Diffusion Osmotic pressure Bulk transport ** Receptor-mediated endocytosis
 * From higher concentration to lower concentration
 * Membranes are selectively permeable
 * Ions diffuse through membrane channels
 * Selective
 * Movement determined by diffusion and voltage differences
 * Facilitated diffusion
 * Carrier protein, physically binds transported molecule
 *  Osmosis
 * Diffusion of water down concentration gradient
 * In cell: various solutes (amino acids, ions, sugars, etc.)
 * interact with water, e.g., hydration shells
 * Water moves through aquaporin channels into cell
 * Depends upon the concentration of all solutes in solution
 * Hyperosmotic solution: higher concentration of solutes
 * Hypoosmotic solution: lower concentration of solutes
 * Isoosmotic solution: solute concentrations equal
 * Water moves from hypoosmotic solution to hyperosmotic solution
 * Endocytosis: energy requiring
 * Phagocytosis
 * Solid material, typically food
 * Pinocytosis
 * Primarily liquid
 * Pits on cell surface coated with clathrin and receptors
 * Bind specific proteins
 * Exocytosis
 * Discharge of materials from vesicle at cell surface

Receptor-mediated endocytosis
Active transport Cotransport (coupled transport)
 * Energy required (usuallyننةىة
 * Highly selective
 * Works against concentration gradient
 * Many examples, e.g., Na+/K+ pump
 * Does not use ATP directly
 * Molecule is transported in connection with another molecule that is moving down a concentration gradient
 * Example: Na+ gradient is established by a Na+ pump, with higher concentration on outside of cell. Cotransport channel carries Na+ and another molecule (e.g. glucose) into cell
 * May involve proton (H+) pumps (chemiosmosis - ATP production)

This text is based on notes very generously donated by Dr. Paul Doerder, Ph.D., of the Cleveland State University.

title: General Biology/Cells/Membranes


text:
General Biology/Cells/Cell-Cell Interactions

=Cell-cell interactions= Cells interact with the environment and with each other.

Cell signaling

 * Signaling requires
 * Signal
 * Cell receptor (usually on the surface of a membrane)
 * Signaling is important in:
 * Response to environmental stimuli
 * Sex
 * Development
 * Major area of research in biology today

Types of signaling

 * Direct contact (e.g., gap junctions between cells)
 * Paracrine: Diffusion of signal molecules in extracellular fluid; highly local
 * Endocrine: Signal (hormone) molecule travels through circulatory system
 * Synaptic: neurotransmitters

Types of signal molecules

 * Hormones: chemically diverse
 * Steroid
 * Polypeptide
 * Vitamin/amino acid derived
 * Cell surface proteins/glycoproteins
 * Ca2+, NO
 * Neurotransmitter
 * Several hundred types
 * Some are also hormones e.g. Estrogen, progesterone

Receptor molecules

 * Intracellular
 * Protein that binds signal molecule in cytoplasm
 * Bound receptor may act as:
 * Gene regulator
 * Enzyme
 * Cell surface
 * Gated ion channels (neurotransmitter receptor)
 * Enzymic receptors
 * G protein-linked receptors

Cell surface protein

 * Tissue identity
 * glycolipids
 * MHC proteins
 * Immune systems
 * distinguish self from not-self
 * Intercellular adhesion
 * permanent contact
 * help form sheets of cells, tissues
 * may permit signaling

Example: G proteins

 * Transmembrane surface receptor binds signal molecule
 * Conformational change allows binding of G protein on cytoplasmic side
 * G protein binds GTP, becomes activated
 * G protein activates intracellular signal cascade
 * Change in gene expression
 * Secrection
 * Many other possible consequences

Communicating junctions

 * Gap junctions
 * animals
 * small molecules and ions may pass
 * Plasmodesmata
 * plants
 * lined with plasma membrane
 * permit passage of water, sugars, etc.

Gap junctions
This text is based on notes very generously donated by Dr. Paul Doerder, Ph.D., of the Cleveland State University.


text:
Interlingua

Interlingua is an international auxiliary language that uses simple grammar and vocabulary common among Romance and Germanic languages. This means that it is a great option for speakers of those languages looking to learn another, or for speakers of other languages who are looking for a nice gateway in English, Italian, Spanish, French, German, etc.

 * Read the Wikipedia article on "Interlingua"
 * Textbooks in English on Interlingua:
 * /On the Grammar of Interlingua/
 * /Basic Interlingua English Dictionary/
 * /Profanity/
 * Libros de texto in Interlingua:
 * /Curso de conversation/ per Harleigh Kyson.

title: Interlingua


text:
General Biology/Cells/Energy and Metabolism

Energy

 * The capacity to do work.
 * Kinetic energy: energy of motion (ex. jogging).
 * Potential energy: stored energy (ex. a lion that is about to leap on its prey).
 * Many forms of energy: e.g.,
 * Heat
 * Sound
 * Electric current
 * Light
 * All convertible to heat
 * Most energy for biological world is from sun
 * Heat (energy of random molecular motion, thermal energy)
 * Convenient in biology
 * All other energy forms can be converted to heat
 * Thermodynamics: study of thermal energy
 * Heat typically measured in kilocalories
 * Kcal: 1000 calories
 * 1 calorie: amount of heat required to raise the temperature of one gram of water one degree Celsius (°C)
 * Heat plays major role in biological systems
 * Ecological importance
 * Biochemical reactions

Oxidation–Reduction

 * Energy flows into biological world from sun
 * Light energy is captured by photosynthesis
 * Light energy raises electrons to higher energy levels
 * Stored as potential energy in covalent C-H bonds of sugars
 * Strength of covalent bond is measured by amount of energy required to break it
 * 98.8 kcal/mole of C-H bonds
 * In chemical reaction, energy stored in covalent bonds may transfer to new bonds. When this involves transfer of electrons, it is oxidation–reduction reaction
 * Always take place together
 * Electron lost by atom or molecule through oxidation is gained by another atom or molecule through reduction
 * Potential energy is transferred from one molecule to another (but never 100%)
 * Often called redox reactions
 * Photosynthesis
 * Cellular Respiration
 * Chemiosynthesis
 * Autotrophs
 * Heterotrophs

NAD+

 * Common electron acceptor/donor in redox reactions
 * Energetic electrons often paired with H+

Free energy

 * Energy required to break and subsequently form other chemical bonds
 * Chemical bonds: sharing of electrons, tend to hold atoms of molecule together
 * Heat, by increasing atomic motion, makes it easier to break bonds (entropy)
 * Energy available to do work in a system
 * In cells, G = H - TS
 * G = Gibbs’ free energy
 * H = H (enthalpy) energy in molecule’s chemical bonds
 * TS (T, temperature in °K; S, entropy)
 * Chemical reactions break and make bonds, producing changes in energy
 * Under constant conditions of temperature, pressure and volume, ΔG = ΔH - TΔS
 * ΔG, change in free energy
 * If positive (+), H is higher, S is lower, so there is more free energy; endergonic reaction, does not proceed spontaneously; require input of energy (e.g., heat)
 * If negative (–), H is lower, S is higher. Product has less free energy; exergonic; spontaneous

Activation energy

 * Reactions with –ΔG often require activation energy
 * e.g., burning of glucose
 * Must break existing bonds to get reaction started
 * Catalysts lower activation energy

Enzymes

 * Biological catalysts
 * Protein
 * RNA (ribozyme)
 * Stabilizes temporary association between reactants (substrates) to facilitate reaction
 * Correct orientation
 * Stressing bonds of substrate
 * Lower activation energy
 * Not consumed (destroyed) in reaction

Carbonic anhydrase

 * Important enzyme of red blood cells
 * CO2 + H2O → H2CO3 -> HCO3 + H+
 * Carbonic anhydrase catalyzes 1st reaction
 * Converts water to hydroxyl
 * Orients the hydroxyl and CO2

Enzyme mechanism

 * One or more active sites which bind substrates (reactants)
 * Highly specific
 * Binding may alter enzyme conformation, inducing better fit

Factors affecting enzyme activity

 * Substrate concentration
 * Product concentration
 * Cofactor concentration
 * Temperature
 * pH
 * Inhibitors
 * Competitive: bind to active site
 * Noncompetitive: bind to 2nd site, called allosteric site; changes enzyme conformation
 * Activators
 * Bind to allosteric sites, increase enzyme activity

Cofactors

 * Required by some enzymes
 * Positively charged metal ions
 * e.g., ions of Zn, Mo, Mg, Mn
 * Draw electrons away from substrate (stress chemical bonds)
 * Non-protein organic molecules (coenzymes)
 * E.g., NAD+, NADP+, etc.
 * Major role in oxidation/reduction reactions by donating or accepting electrons

ATP

 * Adenosine triphosphate
 * Major energy currency of cells, power endergonic reactions
 * Stores energy in phosphate bonds
 * Highly negative charges, repel each other
 * Makes these covalent bonds unstable
 * Low activation energy
 * When bonds break, energy is transferred
 * ATP → ADP + Pi + 7.3 kcal/mole

Biochemical pathways
Evolution of biochemical pathways
 * Metabolism: sum of chemical reactions in cell/organism
 * Many anabolic and catabolic reactions occur in sequences (biochemical pathways)
 * Often highly regulated
 * Protobionts or 1st cells likely used energy rich substrates from environment
 * Upon depletion of a substrate, selection would favor catalyst which converts another molecule into the depleted molecule
 * By iteration, pathway evolved backward


text:
General Biology/Cells/Respiration

Glucose + O2 → CO2 + H2O + ATP

Energy

 * Energy is primarily in C-H bonds (C-O too)
 * Chemical energy drives metabolism
 * Autotrophs: harvest energy through photosynthesis or related process (plants, algae, some bacteria)
 * Heterotrophs: live on energy produced by autotrophs (most bacteria and protists, fungi, animals)
 * Digestion: enzymatic breakdown of polymers into monomers
 * Catabolism: enzymatic harvesting of energy
 * Respiration: harvesting of high energy electrons from glucose

Respiration

 * Transfer of energy from high energy electrons of glucose to ATP
 * Energy depleted electron (with associated H+) is donated to acceptor molecule
 * Aerobic respiration: oxygen accepts electrons, forms water
 * Anaerobic respiration: inorganic molecule accepts hydrogen/electron
 * Fermentation: organic molecule accepts hydrogen/electron

Respiration of glucose

 * C6H12O6 + 6 O2 → 6 CO2 + 6 H2O + energy
 * ΔG = -720 kcal/mole under cellular conditions
 * Largely from the 6 C-H bonds
 * Same energy whether burned or catabolized
 * In cells, some energy produces heat, most is transferred to ATP

Alternative anaerobic respiration

 * Methanogens (Archaebacteria).
 * CO2 is electron acceptor, forming CH4
 * Sulfur bacteria
 * SO4 reduced to H2S
 * Formation of H2S set stage for evolution of photosynthesis (H2S as electron donor before H2O)
 * About 2.7 by, based on ratio of 32S/34S, where only biological processes produce 32S enrichment

Glycolysis overview
Glycolysis accounting 2NADH 4 ATP (from 2 G3P) –2 ATP (priming) 2 ATP (net gain)
 * Oxidation
 * Two electrons (one proton) are transferred from each G3P to NAD+ forming NADH
 * Substrate level phosphorylation
 * G3P to pyruvate forms 2 ATP molecules

Summary: The net input of glycolysis is 2 ATP molecules which are used to split one glucose molecule. The net yield of this step is 2 ATP and 2 pyruvate.

Regeneration of NAD+

 * Reduction of NAD+ to NADH can deplete NAD+ supply; it must be regenerated
 * Two pathways, coupled to fate of pyruvate
 * With oxygen: enter electron transport chain, forming water (and ATP)
 * Without oxygen: fermentation
 * lactate
 * ethanol

Lactate formation
Either lactic acid or alcohol can be formed as a result of anaerobic respiration in cells.

Krebs cycle: overview

 * Matrix of mitochondrion
 * Priming steps
 * Joining of acetyl-CoA to oxaloacetate
 * Isomerization reactions
 * Energy extraction steps in Krebs cycle
 * Per glucose
 * 6 NADH
 * 2 FADH2
 * 2 ATP (from GTP)
 * 4 CO2

ATP production

 * Chemiosmosis (Mitchell)
 * H+ (from NADH and FADH2) is pumped against a gradient into the intermembranal space of the mitochondrion (creates voltage potential)
 * Diffusion back into matrix through ATP synthase channels drives synthesis of ATP (ADP + Pi → ATP)
 * ATP exits mitochondrion by facilitated transport

Evolution of aerobic respiration

 * Preceded by evolution of photosynthesis (O2 needed; also, prior evolution of electron transport and chemiosmosis)
 * High efficiency of ATP production compared to glycolysis
 * Fostered evolution of heterotrophs
 * Fostered evolution of mitochondria by endosymbiosis in eukaryotes

title: General Biology/Cells/Respiration


text:
General Biology/Cells/Photosynthesis

6 CO2 + 6 H2O → C6H12O6 + 6 O2

 * One of most important reactions in history of life:
 * source of atmospheric O2
 * ultimately led to aerobic respiration and eukaryotes
 * Responsible for bulk of glucose production
 * Early experiments showed that mass of plant must be derived from substances in the air, not the soil
 * Experiments with isotopes showed that liberated oxygen comes from water
 * Experiments also showed that light is essential but that some reactions (e.g., reduction of CO2) continue in the dark
 * Plants do two big, important things during photosynthesis: gain energy (absorb light) and build sugar (glucose).
 * Photosynthesis can be divided into two series of chemical reactions: the light (light-dependent) reactions and the dark (light-independent) reactions. In light reactions, light is absorbed; in dark reactions, sugar is built.
 * Occurs when plants, algae, and autotrophic bacteria absorb light energy and build glucose.

Light Reactions

 * Part of the electromagnetic spectrum
 * Consists of units of energy called photons
 * Photons at UV end of spectrum have more energy than those at the red end
 * Occur on the surface of thylakoid disks
 * Chlorophyll and other plant pigments differentially absorb photons
 * Chlorophyll a: light to chemical energy
 * Chlorophyll b: accessory chlorophyll
 * Chlorophylls absorb primarily blue and red (green reflected back, hence the green color of plants)

Accessory pigments
Photosynthetic steps
 * Chlorophyll is a major light gathering pigment
 * Absorbs light with considerable efficiency (i.e., retaining energy)
 * Accessory pigments
 * Chlorophyll b
 * Carotenoinds
 * capture light of wavelengths not captured by chlorophylls
 * Confer other colors to plant leaves (autumn colors too)
 * Primary photoevent: light photon captured by photosystem and energy transferred to electron donated by water
 * Electron transport: excited electron is shuttled along imbedded series of electron carriers to proton pump and electron is transferred to acceptor
 * Chemiosmosis: transport of protons back into chloroplast drives synthesis of ATP

The Even More Detailed Light Reactions
What the Light Reactions Do:

The light reactions of photosynthesis occur in chloroplasts in and on the thylakoid disks. During the light reactions, light energy charges up ATP molecules. More specifically, light turns the chloroplast into an acid battery, and this battery charges up ATP.

How the "Chloroplast-Battery" Charges ATP:

The stroma is the fluid inside of the chloroplasts, and it carries a negative charge. This means that it contains about a "gazillion" extra electrons. The solvent of stroma is water.

The fluid inside the thylakoid disks is positively charged because it contains a lot of hydrogen (H+) ions. The pH here is low, making the fluid very acidic. The solvent of thylakoid disk fluid is water.

A chloroplast acts like a battery, because it has separated a strong positive charge and a strong negative charge in two different compartments. Energy is released when H+ ions (free protons) flow from the inside of a thylakoid disk to the stroma. This is electrical energy, since it is a flow of charged particles.

The protons pass through special channels (made of protein) in the thylakoid membrane; this reaction is 'exothermic.' The energy that is given off is used to fuel this reaction (Pi is the phosphate ion): ADP + Pi --> ATP

The proton can go to the negative stroma, but only if it uses its energy to charge up ATP. Since one reaction wants to go, and the other one doesn't, and since the first reaction releases energy and the second one absorbs energy, the two reactions are known to be 'coupled' together so that the first fuels the second. Of course, a special enzyme must be involved for this to happen.

Chlorophyll Molecules on a Thylakoid Disk:

Hundreds of chlorophyll molecules cover the surface of a thylakoid disk, making the disk green. The nonpolar "tails" of the chlorophyll molecule are embedded in the membrane of the thylakoid.

“Dark” reactions

 * ATP drives endergonic reactions
 * NADPH provides hydrogens for reduction of CO2 to carbohydrate (C-H bonds)
 * Occur in the stroma
 * First step in carbon fixation

The Detailed Dark Reactions
What the Dark Reactions Do:

The dark reactions build sugar from carbon dioxide gas (CO2), water (H2O), and energy from ATP molecules that were charged up during the light reactions. The dark reactions occur in the stroma of a chloroplast. Dark reactions usually occur in the light, but they don't have to. They'll occur in the dark until the chloroplast's supply of ATP runs out (usually about 30 seconds).

The Calvin Cycle:

The Calvin Cycle is the fancy name for the metabolic pathway that builds sugar. This means that it involves a whole lot of chemical reactions, and it uses a lot of different enzymes to catalyze the reactions.

Carbon dioxide gas is stable, therefore the bonds that hold the carbon and oxygen atoms are strong. Therefore it takes a lot of energy to break the bonds and separate the carbon atoms from the oxygen atoms. The energy needed to do this comes from ATP molecules.

When inorganic carbon (like from CO2) is being added to an organic molecule (such as sugar), this is called carbon fixation.

It takes 2 complete turns of the Calvin Cycle to make a glucose molecule.

title: General Biology/Cells/Photosynthesis