text:
C++ Programming/Templates

Templates
Templates are a way to make code more reusable. Trivial examples include creating generic data structures which can store arbitrary data types. Templates are of great utility to programmers, especially when combined with multiple inheritance and operator overloading. The Standard Template Library (STL) provides many useful functions within a framework of connected templates.

As templates are very expressive they may be used for things other than generic programming. One such use is called template metaprogramming, which is a way of pre-evaluating some of the code at compile-time rather than run-time. Further discussion here only relates to templates as a method of generic programming.

By now you should have noticed that functions that perform the same tasks tend to look similar. For example, if you wrote a function that prints an int, you would have to have the int declared first. This way, the possibility of error in your code is reduced, however, it gets somewhat annoying to have to create different versions of functions just to handle all the different data types you use. For example, you may want the function to simply print the input variable, regardless of what type that variable is. Writing a different function for every possible input type (double, char *, etc. ...) would be extremely cumbersome. That is where templates come in.

Templates solve some of the same problems as macros, generate "optimized" code at compile time, but are subject to C++'s strict type checking.

Parameterized types, better known as templates, allow the programmer to create one function that can handle many different types. Instead of having to take into account every data type, you have one arbitrary parameter name that the compiler then replaces with the different data types that you wish the function to use, manipulate, etc.

 * Templates are instantiated at compile-time with the source code.
 * Templates are type safe.
 * Templates allow user-defined specialization.
 * Templates allow non-type parameters.
 * Templates use “lazy structural constraints”.
 * Templates support mix-ins.

Templates are pretty easy to use, just look at the syntax:
 * Syntax for Templates :

(or, equivalently, and preferred by some)

Function template
There are two kinds of templates. A function template behaves like a function that can accept arguments of many different types. For example, the Standard Template Library contains the function template max(x, y) which returns either x or y, whichever is larger. max could be defined like this:

This template can be called just like a function:

The compiler determines by examining the arguments that this is a call to max(int, int) and instantiates a version of the function where the type TYPEPARAMETER is <tt>int</tt>.

This works whether the arguments <tt>x</tt> and <tt>y</tt> are integers, strings, or any other type for which it makes sense to say "<tt>x</tt> < <tt>y</tt>". If you have defined your own data type, you can use operator overloading to define the meaning of  for your type, thus allowing you to use the <tt>max</tt> function. While this may seem a minor benefit in this isolated example, in the context of a comprehensive library like the STL it allows the programmer to get extensive functionality for a new data type, just by defining a few operators for it. Merely defining <tt><</tt> allows a type to be used with the standard <tt>sort</tt>, <tt>stable_sort</tt>, and <tt>binary_search</tt> algorithms; data structures such as s, heaps, and associative arrays; and more.

As a counterexample, the standard type <tt>complex</tt> does not define the <tt><</tt> operator, because there is no strict order on complex numbers. Therefore  will fail with a compile error if x and y are <tt>complex</tt> values. Likewise, other templates that rely on <tt><</tt> cannot be applied to <tt>complex</tt> data. Unfortunately, compilers historically generate somewhat esoteric and unhelpful error messages for this sort of error. Ensuring that a certain object adheres to a method protocol can alleviate this issue.

<tt>{TYPEPARAMETER}</tt> is just the arbitrary TYPEPARAMETER name that you want to use in your function. Some programmers prefer using just <tt>T</tt> in place of <tt>TYPEPARAMETER</tt>.

Let us say you want to create a swap function that can handle more than one data type... something that looks like this:

The function you see above looks really similar to any other swap function, with the differences being the template <class SOMETYPE> line before the function definition and the instances of SOMETYPE in the code. Everywhere you would normally need to have the name or class of the datatype that you're using, you now replace with the arbitrary name that you used in the template <class SOMETYPE>. For example, if you had SUPERDUPERTYPE instead of SOMETYPE, the code would look something like this:

As you can see, you can use whatever label you wish for the template TYPEPARAMETER, as long as it is not a reserved word.

Class template
A class template extends the same concept to classes. Class templates are often used to make generic containers. For example, the STL has a linked list container. To make a linked list of integers, one writes <tt>list<int></tt>. A list of strings is denoted <tt>list<string></tt>. A <tt>list</tt> has a set of standard functions associated with it, which work no matter what you put between the brackets.

If you want to have more than one template TYPEPARAMETER, then the syntax would be:

Let us say that rather than create a simple templated function, you would like to use templates for a class, so that the class may handle more than one datatype. You may have noticed that some classes are able to accept a type as a parameter and create variations of an object based on that type (for example the classes of the STL container class hierarchy). This is because they are declared as templates using syntax not unlike the one presented below:
 * Templates and Classes

Defining member functions of a template class is somewhat like defining a function template, except for the fact, that you use the scope resolution operator to indicate that this is the template classes' member function. The one important and non-obvious detail is the requirement of using the template operator containing the parametrized type name after the class name.

The following example describes the required syntax by defining functions from the example class above.

As you may have noticed, if you want to declare a function that will return an object of the parametrized type, you just have to use the name of that parameter as the function's return type.

Advantages and disadvantages
Some uses of templates, such as the <tt>max</tt> function, were previously filled by function-like preprocessor macros.

Both macros and templates are expanded at compile time. Macros are always expanded inline; templates can also be expanded as inline functions when the compiler deems it appropriate. Thus both function-like macros and function templates have no run-time overhead.

However, templates are generally considered an improvement over macros for these purposes. Templates are type-safe. Templates avoid some of the common errors found in code that makes heavy use of function-like macros. Perhaps most importantly, templates were designed to be applicable to much larger problems than macros. The definition of a function-like macro must fit on a single logical line of code.

There are three primary drawbacks to the use of templates. First, many compilers historically have very poor support for templates, so the use of templates can make code somewhat less portable. Second, almost all compilers produce confusing, unhelpful error messages when errors are detected in template code. This can make templates difficult to develop. Third, each use of a template may cause the compiler to generate extra code (an instantiation of the template), so the indiscriminate use of templates can lead to code bloat, resulting in excessively large executables.

The other big disadvantage of templates is that to replace a #define like max which acts identically with dissimilar types or function calls is impossible. Templates have replaced using #defines for complex functions but not for simple stuff like max(a,b). For a full discussion on trying to create a template for the #define max, see the paper "Min, Max and More" that Scott Meyer wrote for C++ Report in January 1995.

The biggest advantage of using templates, is that a complex algorithm can have a simple interface that the compiler then uses to choose the correct implementation based on the type of the arguments. For instance, a searching algorithm can take advantage of the properties of the container being searched. This technique is used throughout the C++ standard library.

Linkage problems
While linking a template-based program consisting over several modules spread over a couple files, it is a frequent and mystifying situation to find that the object code of the modules won't link due to 'unresolved reference to (insert template member function name here) in (...)'. The offending function's implementation is there, so why is it missing from the object code? Let us stop a moment and consider how can this be possible.

Assume you have created a template based class called Foo and put its declaration in the file Util.hpp along with some other regular class called Bar:

Now, to adhere to all the rules of the art, you create a file called Util.cc, where you put all the function definitions, template or otherwise:

and, finally:

Next, you compile the module, there are no errors, you are happy. But suppose there is another (main) module in the program, which resides in MyProg.cc:

This also compiles clean to the object code. Yet when you try to link the two modules together, you get an error saying there is an undefined reference to Foo ::some_yet_other function in MyProg.cc. You defined the template member function correctly, so what is the problem?

As you remember, templates are instantiated at compile-time. This helps avoid code bloat, which would be the result of generating all the template class and function variants for all possible types as its parameters. So, when the compiler processed the Util.cc code, it saw that the only variant of the Foo class was Foo, and the only needed functions were:

No code in Util.cc required any other variants of Foo or its methods to exist, so the compiler generated no code other than that. There is no implementation of some_yet_other_function in the object code, just as there is no implementation for

or

The MyProg.cc code compiled without errors, because the member function of Foo it uses is correctly declared in the Util.hpp header, and it is expected that it will be available upon linking. But it is not and hence the error, and a lot of nuisance if you are new to templates and start looking for errors in your code, which ironically is perfectly correct.

The solution is somewhat compiler dependent. For the GNU compiler, try experimenting with the -frepo flag, and also reading the template-related section of 'info gcc' (node "Template Instantiation": "Where is the Template?") may prove enlightening. In Borland, supposedly, there is a selection in the linker options, which activates 'smart' templates just for this kind of problem.

The other thing you may try is called explicit instantiation. What you do is create some dummy code in the module with the templates, which creates all variants of the template class and calls all variants of its member functions, which you know are needed elsewhere. Obviously, this requires you to know a lot about what variants you need throughout your code. In our simple example this would go like this:

1. Add the following class declaration to Util.hpp:

2. Add the following member function definition to Util.cc:

Of course, you never need to actually instantiate the Instantiations class, or call any of its methods. The fact that they just exist in the code makes the compiler generate all the template variations which are required. Now the object code will link without problems.

There is still one, if not elegant, solution. Just move all the template functions' definition code to the Util.hpp header file. This is not pretty, because header files are for declarations, and the implementation is supposed to be defined elsewhere, but it does the trick in this situation. While compiling the MyProg.cc (and any other modules which include Util.hpp) code, the compiler will generate all the template variants which are needed, because the definitions are readily available.

title: C++ Programming/Templates


text:
C++ Programming/Compiler/Linker/Libraries

Libraries
Libraries allow existing code to be reused in a program. Libraries are like programs except that instead of relying on main to do the work you call the specific functions provided by the library to do the work. Functions provide the interface between the program being written and the library being used. This interface is called Application Programming Interface or API.

Libraries should and tend to be domain specific as to permit greater mobility across applications, and provide extended specialization. Libraries that are not, are often header only distribution, intended for static linking as to permit the compiler and the application, only to use the needed bits of code.

As seen in the File organization Section, compiled libraries consists in C++ headers files that are included by the preprocessor and binary library files which are used by the linker to generate the resulting compilation. For a dynamically linked library, only the loading code is added to the compilation that uses them, the actual loading of the library is done in the memory at run-time.

Programs can make use of libraries in two forms, as static or dynamic depending on how the programmer decides to distribute its code or even due to the licensing used by third party libraries, the static and dynamic libraries section of this book will cover in depth this subject.

Third party libraries
Additional functionality that goes beyond the standard libraries (like garbage collection) are available (often free) by third party libraries, but remember that third party libraries do not necessarily provide the same ubiquitous cross-platform functionality or an API style conformant with as standard libraries. The main motivation for their existence is to avoid having to reinvent the wheel and to make efforts converge; too much energy has been spent by generations of programmers to write safe and "portable" code.

There are several libraries a programmer is expected to know about or have at least a passing idea of what they are. Time, consistency and extended references will make a few libraries pop-out from the rest. One notable example is the highly respected collection of Boost libraries that we will examine ahead.

The programmer may also be limited by the requirements of the license used on external libraries that he has no direct control, for instance the use of the GNU General Public License (GNU GPL) code in closed source applications isn't permitted to address this issue the FSF provides an alternative in the form of the GNU LGPL license that permits such uses but only in the dynamically linked form, this is mirrored by several other legal requirements a programmer must attend and comply to.
 * Licensing on third party libraries

Libraries come in two forms, either in source form or in compiled/binary form. Libraries in source-form must first be compiled before they can be included in another project. This will transform the libraries' cpp-files into a lib-file. If a program must be recompiled to run with a new version of a library, but does not need any further changes, the library is said to be source compatible. If a program does not need to be modified and recompiled to use a new version of a library, the library is then classified as being binary compatible.

Another distinction that is commonly made about libraries are on how they are distributed (regarding structure and use). A library that is contained only on header files is considered header-only library. Often this means that they are simpler and easy to use, however this will not be the ideal solution for complex code, it will not only hamper readability but result in larger compile times. Also depending on the compiler and it's optimizing capabilities (or options) can, due to the resulting inlining, generate larger binaries. This may not be as important in libraries mostly implemented with templates. Header-only libraries will always contain the source code to the implementation, commercial is rare.
 * header-only libraries

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


text:
Rhetoric and Composition/Argument

What is An Argument?
When you hear the word "argument," what do you think of? Maybe you think of a shouting match or a fist fight? Well, when instructors use the word "argument," they're typically thinking about something else. What they're actually referring to is a position supported by the analysis that preceded its conception, not necessarily defending against antagonism.

More to the point, they're talking about defending a certain point of view through writing or speech. Usually called a "claim" or a "thesis," this point of view is concerned with an issue that doesn't have a clear right or wrong answer (e.g., four and two make six). Also, this argument should not only be concerned with personal opinion (e.g., I really like carrots). Instead, an argument might tackle issues like abortion, capital punishment, stem cell research, or gun control. However, what distinguishes an argument from a descriptive essay or "report" is that the argument must take a stance; if you're merely summarizing "both sides" of an issue or pointing out the "pros and cons," you're not really writing an argument. "Stricter gun control laws will likely result in a decrease in gun-related violence" is an argument. Note that people can and will disagree with this argument, which is precisely why so many instructors find this type of assignment so useful -- they make you think!

Academic arguments usually "articulate an opinion." This opinion is always carefully defended with good reasoning and supported by plenty of research. Research? Yes, research! Indeed, part of learning to write effective arguments is finding reliable sources(or other documents) that lend credibility to your position. It's not enough to say "capital punishment is wrong because that's the way I feel."

Instead, you need to adequately support your claim by finding:
 * facts
 * statistics
 * quotations from recognized authorities, and
 * other types of evidence

You won't always win, and that's fine. The goal of an argument is simply to:

 * make a claim
 * support your claim with the most credible reasoning and evidence you can muster
 * hope that the reader will at least understand your position
 * hope that your claim is taken seriously

If you defend your argument's position with good reasoning and evidence, you should earn a high grade, even if your instructor personally disagrees with the views you are defending.

We will be covering the basic format of how to structure an argument. This includes the general written argument structure, and the Position and Proposal variations of that basic form. If you want to make a claim about a particular (usually controversial) issue, you can use the Position argument form. Alternately, if you would like to offer a solution to a particular situation that you see as problematic, such as the rising cost of education, you can get your idea across using a Proposal argument. By adapting one of these three methods, you will be well on the way to making your point. The great thing about the argument structure is its amazing versatility. Once you become familiar with this basic structure of the argumentative essay, you will be able to clearly argue about almost anything!

Introduction
The first paragraph of your argument is used to introduce your topic and the issues surrounding it. This needs to be in clear, easily understandable language. Your readers need to know what you're writing about before they can decide if they believe you or not.

Once you have introduced your general subject, it's time to state your claim. Your claim will serve as the thesis for your essay. Make sure that you use clear and precise language. Your reader needs to understand exactly where you stand on the issue. The clarity of your claim affects your readers' understanding of your views. Also, it's a good idea to highlight what you plan to cover. Highlights allow your reader to know what direction you will be taking with your argument.

You can also mention the points or arguments in support of your claim, which you will be further discussing in the body. This part comes at the end of the thesis and can be named as the guide. The guide is a useful tool for you as well as the readers. It is useful for you, because this way you will be more organized. In addition, your audience will have a clear cut idea as to what will be discussed in the body.

Background Information
Once your position is stated, you should establish your credibility. There are two sides to every argument. This means not everyone will agree with your viewpoint. So try to form a common ground with the audience. Think about who may be undecided or opposed to your viewpoint. Take the audience's age, education, values, gender, culture, ethnicity, and all other variables into consideration as you introduce your topic. These variables will affect your word choice, and your audience may be more likely to listen to your argument with an open mind if you do.

Developing Your Argument
Back up your thesis with logical and persuasive arguments. During your pre-writing phase, outline the main points you might use to support your claim, and decide which are the strongest and most logical. Eliminate those which are based on emotion rather than fact. Your corroborating evidence should be well-researched, such as statistics, examples, and expert opinions. You can also reference personal experience. It's a good idea to have a mixture. However, you should avoid leaning too heavily on personal experience, as you want to present an argument that appears objective as you are using it to persuade your reader.

There are a couple different methods of developing your argument. Two variations of the basic argument structure are the Position Method and the Proposal Method.

Position Method
The Position Method is used to try to convince your audience that you are in the right, and the other view of your argument is wrong.

Proposal Method
The Proposal Method of argument is used when there is a problematic situation, and you would like to offer a solution to the situation. The structure of the Proposal method is very similar to the above Position method, but there are slight differences.

Dealing With the Opposition
When writing an argument, expect that you will have opposition. Skeptical readers will have their own beliefs and points of view. When conducting your research, make sure to review the opposing side of the argument that you are presenting. You need to be prepared to counter those ideas. Remember, in order for people to give up their position, they must see how your position is more reasonable than their own. When you address the opposing point of view in your essay and demonstrate how your own claim is stronger, you neutralize their argument. By failing to address a non-coinciding view, you leave a reason for your reader to disagree with you, and therefore weaken your persuasive power. Methods of addressing the opposing side of the argument vary. You may choose to state your main points, then address and refute the opposition, and then conclude. Conversely, you might summarize the opposition's views early in your argument, and then revisit them after you've presented your side or the argument. This will show how your information is more reasonable than their own.

Conclusion
You have introduced your topic, stated your claim, supported that claim with logical and reasonable evidence, and refuted your opposition's viewpoint. The hard work is done. Now it's time to wrap things up. By the time readers get to the end of your paper, they should have learned something. You should have learned something, too. Give readers an idea to take away with them. Conclude = to come together or to end (not restate what has already been said in your paper). One word of caution: avoid introducing any new information in your conclusion. If you find that there's another point that you wanted to include, revise your essay. Include this new information into the body of your essay. The conclusion should only review what the rest of your essay has offered.

Phrasing
It is important to clearly state and support your position. However, it is just as important to present all of the information that you've gathered in an objective manner. Using language that is demeaning or non-objective will undermine the strength of your argument. This destroys your credibility and will reduce your audience on the spot. For example, a student writing an argument about why a particular football team has a good chance of "going all the way" is making a strategic error by stating that "anyone who doesn't think that the Minnesota Vikings deserve to win the Super Bowl is a total idiot." Not only has the writer risked alienating any number of her readers, she has also made her argument seem shallow and poorly researched. In addition, she has committed a third mistake: making a sweeping generalization that cannot be supported.

Objective Language
You should avoid using "I" and "My" (subjective) statements in your argument. You should only use "I" or "My" if you are an expert in your field (on a given topic). Instead choose more objective language to get your point across. Consider the following:

I believe that the United States Government is failing to meet the needs of today's average college student through the under-funding of need-based grants, increasingly restrictive financial aid eligibility requirements, and a lack of flexible student loan options.

"Great," your reader thinks, "Everyone's entitled to their opinion."

Now lets look at this sentence again, but without the "I" at the beginning. Does the same sentence becomes a strong statement of fact without your "I" tacked to the front?:

The United States Government is failing to meet the needs of today's average college student through the underfunding of need-based grants, increasingly restrictive financial aid eligibility requirements, and a lack of flexible student loan options.

"Wow," your reader thinks, "that really sounds like a problem."

A small change like the removal of your "I"s and "my"s can make all the difference in how a reader perceives your argument-- as such, it's always good to proof read your rough draft and look for places where you could use objective rather than subjective language.

The Fallacies of Argument
Okay; your paper is filled with quality research. You're feeling good about your paper. But when you get the paper back your instructor has left a comment like, "This is an argument fallacy". So now you're left wondering what is "false" about the argument; and what is this "argument fallacy"?

Argumentative fallacies are sometimes called "logical fallacies". Usually these "fallacies" are created when the reasoning behind the argument lacks validity. A lack of validity weakens your argument, and then leads to a failure to provide a sufficient claim.

Don't feel badly if your paper says "fallacy of argument" on it. This is a common error in argumentative papers. In fact, a detailed list of "logical fallacies" can be found in the "Common Errors" section of this book (just below "Run-On" sentences and "Sentence Fragments". If you would like to see the list of logical fallacies, please visit The Writers Handbook.

"Argumentative fallacy" can be caused by your 'negligence' or lack of rigor and attention while making a certain argument. In other words, a very general argument, not followed through rigorously, can end up in something as an 'argumentative fallacy'. So, never generalize; don't just say and leave -- pursue your point to its logical termination.

A Side Note
Many topics that are written about in college are very controversial. When approaching a topic it is critical that you think about all of the implications that your argument makes. If, for example, you are writing a paper on abortion, you need to think about your audience. There will certainly be people in each of your classes that have some sort of relationship to this topic that may be different than yours. While you shouldn't let others' feelings sway your argument, you should approach each topic with a neutral mind and stay away from personal attacks. Keep your mind open to the implications of the opposition and formulate a logical stance considering the binaries equally. People may be offended by something you say, but if you have taken the time to think about the ideas that go into your paper, you should have no problem defending it.

title: Rhetoric and Composition/Argument


text:
Talk:Japanese/Introduction/About

Old discussion
I may be confusing this with older chinese, but I remember some older japanese being written right to left occasionally.
 * Hi. Wikipedia has an artile on it: Horizontal and vertical writing in East Asian scripts, although I know almost nothing about right-to-left writing system... Actually, I was puzzled when I saw it for the first time (on old newspaper article or like). - Marsian / talk

Perhaps you're well aware of this matter and dared to put it, but just in case: 行かせられたくならなかった looks too strange (さすがに やりすぎ かな と). If the subject of the phrase is "he", then either 行きたく(は)ならなかった or 行く気に(は)ならなかった is natural. - Marsian / talk 04:14, 19 September 2005 (UTC)

"You won't find much rōmaji in this Wikibook as you are expected to master the reading and writing of Japanese. You will see the rewards instantly when you are able to read Japanese."

 * While this may be good for people who want to learn to read Japanese, isn't this a pretty big set-back for those who just want to learn to speak it and to understand spoken Japanese? - Sik0fewl 00:04, 2 Apr 2005 (UTC)

 * I agree. Also, it's easy to learn to read without learning to write well (you don't need to be able to write to type). - ToothingLummox 12:37, 25 August 2005 (UTC)

Multiple pages merged
Several pages were copied to this one and then marked for speedy deletion. As they had long histories, I merged them instead, and left the old pages up as redirects to this one. The current page history is thus a bit asynchronous, but the old versions are all there. -- SB_Johnny | talk 08:09, 15 September 2006 (UTC)

Mixed Usage section
I was reading this section and it says "は wa (topic marker) and です desu (is/am/are) are written in hiragana". Although I am new to the Japanese language I believe that は is ha in hiragana. Now it might be something that I haven't learned yet and am thus wrong, but I was hoping someone that knows the language might know enough to fix it if it's wrong. Phydend 02:32, 8 April 2007 (UTC)
 * Nevermind, I see that は is pronounced as "wa" when it is a topic marker. Ignore my post above. Phydend 15:40, 9 April 2007 (UTC)
 * Right! ;-) And you will see the same thing in: dewa (では), the particle e (へ) and the particle o (を). Shinjitsu 12:33, 9 November 2007 (UTC)

Grammar section
"Japanese is typically classified as an SOV (Subject Object Verb) language, whereas English is an SVO (Subject Verb Object) language." It is true that Japanese is typically classified as an SOV language, but that does not make it a true statement. Japanese is in fact a "V" language. The sentence structure for Japanese grammar relies on only one thing: its verb. In written Japanese, a grammatically correct sentence ends with a verb; the order of the rest of the sentence - if it exists at all - is variable and mutable depending on the writer's preference. It may change based on the writer's decision for emphasis. When sentences do not stand alone, as is quite usually the case, the context of the sentence is often known in advance, and left out of the sentence entirely. If we're already talking about cats, we will not say, "Neko wa nezumi wo kuu." We will instead say "Nezumi wo kuu."  "Neko wa" is redundant and dismissed. You could even ask "What do cats do with mice?" In English, the answer might be, "They eat them." In Japanese, the answer would simply be "Eat." Verb only.

The section goes on to say that "[as] long as you remember this grammar structure, Japanese won't be so difficult to learn." It is more important, I think, to teach the new student that the sentence structure is even more simple and more flexible, and that will help students most. They will, inevitably, come across structure that defies SOV, and giving the true sentence structure will avoid confusion in the future. Hekirou 15:01, 17 October 2007 (UTC)

 * "[as] long as you remember this grammar structure, Japanese won't be so difficult to learn." Maybe this sentence should be removed. It's not up to us to decide what is difficult and what is not difficult to learn. That is for everybody personal. For a Korean, Japanese should be relatively easy to learn (since the grammatical structure is similar), but for a French it might be very difficult because of the numerous differences in grammatical structure, declinations (present, past, future tense, etc.), pronunciation, etc. Somebody who has been trying to learn it for a while but finds lots of difficulties and then read here that "it's not so difficult to learn" might find it frustrating and demoralizing. Shinjitsu 12:47, 9 November 2007 (UTC)

 * As per above, I have removed the "Japanese won't be difficult to learn", and replaced with the more neutral:
 * Japanese grammar is markedly different from English grammar, but is very regular.
 * ...as Japanese does present difficulties for English-speakers, but is regular.
 * As per Hekirou's comment, I've emphasized the topic-prominent of Japanese, and the pro-drop, giving examples.
 * Nbarth (talk) 00:04, 12 March 2008 (UTC)

Gojūon table

 * The syllabary charts in Japanese are referred to as the 五十音 gojūon, meaning "fifty sounds" because they are written in a five by ten chart. However, three of the fifty original sounds are duplicates, two are obsolete, and an extra one has been added, so that presently there are forty-six in common use.

I'm pretty sure this explanation is incorrect or at least extremely unclear. I'm guessing it was originally worded unclearly by one editor and another editor incorrectly changed it to what they thought it meant. First off, in my understanding, the original gojūon table had 47 sounds. Kana for "ye", "yi", and "wu" never existed (although "we" and "wi" are sometimes romanized as "ye" and "yi"). The only two kana removed from the table were ゑ (we) and ゐ (wi). When you add ん (n'), you do end up with the 46 kana of modern Japanese. Both ゑ and ゐ were indeed "duplicate" sounds as they were actually pronounced "e" and "i", so they were both duplicates and obsolete. を (wo) is also duplicate in sound (pronounced "o"), but not in function, so it was not removed and is still used in modern Japanese. So there were were indeed three duplicate sounds (we, wi, wo) and two obsolete kana (we, wi), but two of these duplicate sounds were the same as the obsolete kana and the remaining one was not removed. So the text appears to be claiming that there were originally 50 kana - 3 duplicates - 2 obsolete + 1 new = 46 kana, but in fact there were originally 47 kana - 2 obsolete + 1 new = 46 kana. So the above text is correct in saying that there are 46 kana in modern Japanese, but it is right for the wrong reason. :) I'm going to change the text myself to say there are a few gaps and leave it at that; why there are only 46 kana in a 5x10 table isn't that important anyway. - Furrykef (talk) 19:34, 22 December 2007 (UTC)

Japanese/Introduction/About
I'm in favour of removing this section. There isn't much content here and I doubt it's much use to people who've already taken the step to find this book. --Swift (talk) 06:21, 12 June 2008 (UTC)
 * I agree in its removal--Balloonguy (talk) 22:40, 12 June 2008 (UTC)
 * I agree on its removal. We should move most of these to the main talk page, so we all know where to see removal suggestions instead of finding them by accident. --Retropunk (talk) 06:07, 14 June 2008 (UTC)
 * Ah, certainly! --Swift (talk) 13:26, 14 June 2008 (UTC)

title: Talk:Japanese/Introduction/About


text:
User talk:Whiteknight

java package save & compile process

 * This message will be archived normally

when a package contain three class then which type we can compile it?

Watching books

 * This message will be archived normally

Is there a way to automatically watch all chapters in a book? I just started a new one (Training the Search and Rescue Dog) and want to watch as it expands.

Sorry to bug again, but you mentioned having links in the TOC to all pages in the book. So far, I've only been able to have the TOC link to the subheadings on the first page. I created some chapters, but these aren't listed in the TOC, which seems kinda backwards to me. Is there some documentation somewhere about getting chapters to show in the TOC?

Gre preparation merge
Hello Whiteknight, Sorry for the late response. Even I had been thinking about the Merge with the GRE book. But the thought we had was, we are going to cover information much more than just GRE, like TOEFL, application process, university selection process. Is it okay that we change the name of the book to something suitable at an later date?

RE: Glossary of terms
Hello,

I am a 78 yearold former programmer/analyst and I find I have been passed by in the field of computers. When I pick up a book to read or for instruction in the new systems I am constantly trying to figure out what is meant by some of the abbreviations and acronyms they use. It gets very confusing. Where can I get a book or list of these things as an aid to understanding what is written.

Thank you,

Ed Burdick

Thanks! (and a couple questions)
Thanks for the info about printable books and locking pages from edits. You are a lifesaver, and I really appreciate all your patience as we all try to ride the learning curve.

Last year, I thought about trying to be an admin, but I stopped short because I wondered how it would look for me to volunteer for a site I researched so much. Do you have any thoughts on that? Girl never  give up  on  something okay  and  I was thinking  about  our  relationship   can  we  be friends  by the way  my  name  is kitty  what  is  your  name

Finally, I was wondering if you'd be willing to post some more rating buttons in our third edition's [[Foundations of Education and Instructional Assessment/Edition 3/Assessment Table of Contents
 * Instructional Assessment section]]. We have posted the first one on A1.1.1, and this rating button is number 271.  As a reminder, the complete rating button looks like this:

Deleting an inactive user (usurping)
Hi, I am contributing mainly to the Hebrew Wikipedia and I merged my username on most wiki projects to User:Daniel1. I noticed that this user is taken on this project. However, it has almost made no contributions and the ones that have been made are very old. Would it be possible to delete / move this username so I can use my merged name on this project too? Thanks, Daniel.

Concurrent Engineering
Hello, White Knight

I appreciate your comment that "Concurrent Engineering" is coming along nicely.

I am a retired engineer back to college as an instructor, teaching from my background in product development.

This is my first experience with 21st century wiki collaboration, and I have yet to learn all the navigation tools that come with. Some of my students are keen and helpful, but not all. The justifiable mantra of "Do your own work, and earn your own grade!" is hard to throw off in the name of cooperation.

Further advice from you will be appreciated

Peter Burke

Sure, who knows what collaboration will arise?

Peter Burke, Instructor Oregon State University, Department of Mechanical, Industrial, and Manufacturing Engineering Corvallis, Oregon

www.engr.oregonstate.edu

Concurrent Engineering wikibook will be undergoing many deliberate changes over the next three weeks.

What is the approval process?

What does Xania have to do with it?

Peter Burke professor trying to get students to create a useful wikibook

signpost story
Hi Andrew! I saw your post about going to Norfolk to meet with these people. Would you be able to write up a Signpost story about the grant? I'd love to promote it, and you're the most knowledgeable. It could be a whole story or a short piece to go into news & notes. Best, -- phoebe

EXIT TICKET
HI MY NAME IS JARON ROBERTSON AND I'M HERE FOR LEARNING HOW THINGS ARE WORKING.

Advertising the LaTeX wikibook
The LaTeX wikibook needs quite a few fixing. Over the years, code got obsolete and some of the advice given even wrong. I'll try to apply some fixes over the next months, but i think for now, any advertisement should be deferred. Who to reach out for?

Johannes Böttcher

LaTeX-community.org

Speedy deletion nomination of "Practical Electronics/Outputs"
Practical Electronics/Outputs, a page you created, has been tagged for deletion, as it meets one or more of the criteria for speedy deletion; specifically, it needs to be deleted for uncontroversial maintenance reasons.

You are welcome to contribute content that complies with our content policies and any applicable inclusion guidelines. However, please do not simply re-create the page with the same content, or remove the speedy deletion tag from the page. You can contest the deletion by clicking the "Contest this speedy deletion" button inside the speedy deletion tag. You may also wish to read our introduction to editing and guide to writing your first article.

Thank you. |Wikibooks=PokestarFan*Talk*Contributions|#default= PokestarFan*Talk*Contributions  }}|Wikibooks=PokestarFan*Talk*Contributions|#default=  PokestarFan*Talk*Contributions  }}|Wikibooks=PokestarFan*Talk*Contributions|#default=  PokestarFan*Talk*Contributions  }}|Wikibooks=PokestarFan*Talk*Contributions|#default=  PokestarFan*Talk*Contributions  }}|Wikibooks=PokestarFan*Talk*Contributions|#default=  PokestarFan*Talk*Contributions  }} 02:57, 16 August 2017 (UTC),

Speedy deletion nomination of "Practical Electronics/Inputs"
Practical Electronics/Inputs, a page you created, has been tagged for deletion, as it meets one or more of the criteria for speedy deletion; specifically, it needs to be deleted for uncontroversial maintenance reasons.

You are welcome to contribute content that complies with our content policies and any applicable inclusion guidelines. However, please do not simply re-create the page with the same content, or remove the speedy deletion tag from the page. You can contest the deletion by clicking the "Contest this speedy deletion" button inside the speedy deletion tag. You may also wish to read our introduction to editing and guide to writing your first article.

Thank you. |Wikibooks=PokestarFan*Talk*Contributions|#default= PokestarFan*Talk*Contributions  }}|Wikibooks=PokestarFan*Talk*Contributions|#default=  PokestarFan*Talk*Contributions  }}|Wikibooks=PokestarFan*Talk*Contributions|#default=  PokestarFan*Talk*Contributions  }}|Wikibooks=PokestarFan*Talk*Contributions|#default=  PokestarFan*Talk*Contributions  }}|Wikibooks=PokestarFan*Talk*Contributions|#default=  PokestarFan*Talk*Contributions  }}|Wikibooks=PokestarFan*Talk*Contributions|#default=  PokestarFan*Talk*Contributions  }} 18:40, 19 August 2017 (UTC),

Think Python/Lists
Which specifc version of this did you import?

I'm finding differences between this and the earliest HTML version I can find in archive.org.

The differences seem to include material from the PDF copy which is under an incompatible CC-NC license. ShakespeareFan00 (discuss • contribs) 06:51, 29 April 2022 (UTC)

Social studies
I love this  subject  so  o o much  how  about  you 🌄 41.77.91.202 (discuss) 17:50, 8 June 2022 (UTC)social studies  is about  life  what  do  you  think about  it Good

I like it very much ❤
@Whiteknight 41.121.17.19 (discuss) 10:05, 10 January 2024 (UTC)

title: User talk:Whiteknight


text:
User:Mshonle/First edition

Still pending.

Will have something to do with making formal the process a book takes to say that it as reached "first edition." The primary purpose is to provide incentives and direction for contributors to take the book to a specific goal.

title: User:Mshonle/First edition


text:
Talk:Consciousness Studies

About

 * Started: 21 June 2005
 * Size: 97,500 words (Apr 2009)

Various
The general layout of the book is in four sections. The first two are a historical review and a discussion of the problems thrown up by the empirical data. These have been merged but could be separated. The third is a presentation of neuroscience as it relates to consciousness and the fourth is about theories that attempt to explain consciousness.

There is a problem with the second section, "the problems raised by the empirical data". In some ways this section could be called 'a hundred ways in which nineteenth century materialism fails to account for consciousness'. This will not be popular with a large caucus of philosophers but scientists need to see that the problem of consciousness, like all unresolved scientific problems, is about a failure of popular theory to account for the empirical data. Scientists must decide where theory fails to provide an elegant description of observation so that they can evolve new theories.

Functionalists and Eliminativists do not need a textbook about consciousness. A sentence will do stating that no-one should doubt that the universe is described by functional presentism hence consciousness can only be reflexive. But eliminativists and functionalists, on reflection, nearly always end up with 'non-reductivism' or 'emergentism' - there are things about consciousness that are not explained by the theory. Given this failure of the nineteenth century approach it is better to be 'up front' and describe "the problems raised by the empirical data" before assuming any theories.

The philosophical explanations of consciousness are hypotheses and need to go at the end of the book. The philosophers who are proponents of philosophical hypotheses may believe that they have argued their validity and hence elevate them above scientific hypotheses but this is largely a scientific textbook and philosophical blarney is no better than protoscience. RobinH 08:22, 19 September 2005 (UTC)

The historical review has now been separated. RobinH 09:23, 21 September 2005 (UTC)

Orphanded pages
I found some orphaded pages that seem to be connected with this book
 * Consciousness studies :Other explanations
 * This page was created in error by a new user of Wikimedia and its content is now at: and can be deleted.

 * Consciousness studies:The philosophical problem - Appendixr
 * This page has been integrated into and was used as a place holder for a while, it can also be deleted. Best wishes User:RobinH

--Derbeth talk 13:06, 11 January 2006 (UTC)

free will
Is "free will" something that needs to be discussed in this book? (see Paul Davies' Really Dangerous Idea ).
 * Interesting article. The big problem is that type 2 "freedom" is deterministic except for chaotic events and these are not "willed". It is doubtful whether type 2 free will qualifies as free will at all according to the intuitions of free will held by ordinary people. The type 2 free will component of a book on consciousness studies would be a module in the access consciousness section. The type 1 free will component would depend upon speculations about the physical nature of phenomenal consciousness. RobinH 11:03, 14 January 2006 (UTC)

New comments go at the bottom
This book has been hjacked by cranks and people who don't really know what they are talking about. It needs to be peer reviewed.

 * The section on the neuroscience of vision is straighforward textbook physiology. As are many of the other sections, including those on philosophy. It is natural for anyone committed to the mid to late twentieth century idea that consciousness is entirely access consciousness to consider the treatment of phenomenal consciousness to be "cranky". Please could you be specific about your problem? RobinH 11:38, 6 April 2006 (UTC)

Audition
I'd love to see a section in part III on the neuroscience of hearing. I know a little about it and there are many interesting auditory anomalies/illusions that could shed some light on this important aspect of consciousness. Music and it's affects, it's role as perhaps "higher" language may prove interesting here also. I'm also certainly not knowledgeable enough to initiate such a section. I'm fairly new to Wikipedia so I hope I've not stepped on any toes. 203.52.129.250
 * I concur, as it is so hard to find credible scientific peer reviewed articles oni the net about subject as the neural correlate of music, and of the perception of music by dogs, alternatives harmonies and such. maybe this book can over it.

Is that really consciousness? It seems like that doesn't fit under the topic. Please explain. I guess if you are talking about hearing only, it fits fine, but if it becomes very music-specific, I think it would better fit under music theory, or something like that. I like the idea though. Marky1991 23:19, 20 December 2006 (UTC)

Link to consciousness survey project at canonizer.com?
The consciousness survey project has as its goal a comprehensive concise and quantitative survey of what are the most well accepted theories of consciousness. Would it be OK to add a link to this, perhaps in the history section of this page, since this is a real time survey, including now more than 2 years of history of a kind of a consensus horse race that is obviously just getting started? The more people that participate in the survey process (canonize their views, if you will) the more comprehensive it becomes. Brent.Allsop (talk) 22:53, 23 January 2010 (UTC)

PDF error
after page 94 the PDF has a display error, preventing further reading..--Diza 11:07, 18 January 2007 (UTC)
 * thanks - now fixed RobinH 12:53, 18 January 2007 (UTC)

title: Talk:Consciousness Studies


text:
Consciousness Studies/Contemporary Explanations

''This section is about the types of theory that have been advanced to explain consciousness. Specific explanations should be entered as separate pages.''

Introduction
Explanations of consciousness fall into three broad categories, those that attempt to explain the empirical experience called consciousness with scientific theories, those that seek to find some way in which consciousness could be explained by digital computers or nineteenth century materialism by redefining or eliminating experience and those that regard consciousness as inexplicable or supernatural.

Identity theory of mind
The identity theory of mind, or type physicalism, holds that the mind is identical to the brain. Type physicalists identify qualia and the form of experience with brain activity. They argue that "mind states" have physical causes and physical effects - thus the mind states themselves must be physical; a non-physical "middle step" is superfluous.

Type physicalism has not yet gained widespread support because although brain activity that correlates with experience has been found everywhere in the brain, no set of brain activity that is phenomenal consciousness itself has yet been found - although this is not surprising because neuronal spike activity is unlikely to host phenomenal consciousness - see scientific theories of consciousness.

Functionalism
Functionalism was developed as a theory of the mind-body problem because of objections to identity theory and logical behaviourism. Its core idea is that the mental states can be accounted for without taking into account the underlying physical medium (the neurons), instead attending to higher-level functions such as beliefs, desires, and emotions. It is a theory of behaviour and access consciousness and so from the outset avoids any explanation of phenomenal consciousness, substituting beliefs and judgements (functions) for entities such as qualia.

According to functionalism, the mental states that make up consciousness can essentially be defined as complex interactions between different functional processes. Because these processes are not limited to a particular physical state or physical medium, they can be realized in multiple ways, including, theoretically, within non-biological systems.This affords consciousness the opportunity to exist in non-human minds that are based on algorithmic processors such as digital computers. This is a highly contentious conjecture although non-functionalist physicalists might agree that machines that are not digital computers could possess consciousness through an identity theory of mind - see The problem of machine and digital consciousness.

Functionalism's explanation of consciousness, or the mental, is best understood when considering the analogy made by functionalists between the mind and the modern digital computer. More specifically, the analogy is made to a "machine" capable of computing any given algorithm (i.e. a Turing machine). This machine would involve:

Data input (the senses in humans), data output (both behaviour and memory), functional states (mental states), the ability to move from one functional state into another, and the definition of functional states with reference to the part they play in the operation of the entire entity - i.e. in reference to the other functional states. So long as the same process was achieved, the "physical stuff" -- that being computer hardware or biological structure -- could achieve consciousness.

This variety of functionalism was developed by Hilary Putnam. One of the major proponents of functionalism is Jerry Fodor.

Further reading:

Block, N. (1996). The Encyclopedia of Philosophy Supplement, Macmillan, 1996 http://www.nyu.edu/gsas/dept/philo/faculty/block/papers/functionalism.pdf

Substance dualism
This theory proposes that phenomenal experience occurs in a non-physical place. In Cartesian Dualism the non-physical place is an unextended soul that looks out at the brain. In Reid's Natural Dualism the non-physical place is a point-soul that looks out at the world.

Property dualism
Property dualism asserts that when matter is organized in the appropriate way (i.e., organized in the way that living human bodies are organized), mental properties emerge. Property dualism is a branch of emergent materialism. The appeal to emergentism deserves closer attention. Scientific theories often deal with emergent phenomena, for instance an enzyme consists of carbon, hydrogen, nitrogen, manganese and oxygen and from this catalytic action emerges. The theory of enzyme structure and the action of this structure on the substrate explains how this emergence occurs. Notice that the theory of enzymes explains the emergence of catalytic activity; emergence does not explain the theory. In science the statement that some property will 'emerge' means that there will be a theory that accounts for this property. Property dualism, by appealing to emergence, is stating that some theory of consciousness will be possible. In other words it is an explanation that proposes that the explanation is yet to be known.

Higher order thought
This section is a stub and needs expansion

Eliminativism
Eliminative materialism is the school of thought that argues for an absolute version of materialism with respect to mental entities and mental vocabulary. It principally argues that our common-sense understanding of the mind (often called 'folk psychology') is not a viable theory on which to base scientific investigation, and therefore no coherent neural basis will be found for many such everyday psychological concepts (such as belief or intention) and that behaviour and experience can only be adequately explained on the biological level.

Eliminative materialists therefore believe that consciousness does not exist and that the concept will eventually be eliminated as neuroscience progresses. Similarly, they argue that folk psychological concepts such as belief, desire and intention do not have any consistent neurological substrate.

Proponents of this view often make parallels to previous scientific theories which have been eliminated, such as the four humours theory of medicine, the phlogiston theory of combustion and 'vital force' theory of life. In these cases, science has not produced more detailed versions of these theories, but rejected them as obsolete. Eliminative materialists argue that folk psychology is headed the same way. According to W.V. Quine it will take tens of years before folk psychology will be replaced with real science. (see Phenomenal consciousness and access consciousness).

Eliminative materialism was first defended by W.V. Quine, Paul Feyerabend, and Richard Rorty. This view is most associated with philosophers Paul and Patricia Churchland although philosophers such as Daniel Dennett would also consider themselves eliminativists for many aspects of psychology. Philosopher Dale Jacquette has claimed that Occam's Razor is the rationale behind eliminativism and reductionism.

The most common argument against eliminative materialism is the argument from qualia, which is deployed in various forms by Thomas Nagel, Frank Jackson, and many others. Perhaps the most powerful argument against eliminativism is that experience itself is many things simultaneously; it is, as Aristotle points out, immediate and hence is not composed of judgements.

Mysterianism
New Mysterianism is a philosophy proposing that certain problems (in particular, consciousness) will never be explained.

Owen Flanagan noted in his 1991 book "Science of the Mind" that some modern thinkers have suggested that consciousness might never be completely explained. Flanagan called them "the new mysterians" after the rock group ? and the Mysterians. The term originated with the Japanese alien-invasion film The Mysterians. The "old mysterians" are thinkers throughout history who have put forward a similar position. They include Leibniz, Dr Johnson, and Thomas Huxley. The latter said, "How is it that anything so remarkable as a state of consciousness comes about as a result of irritating nervous tissue, is just as unaccountable as the appearance of the Djin, when Aladdin rubbed his lamp." [6, p. 229, quote]

Noam Chomsky distinguishes between problems, which seem solvable, at least in principle, through scientific methods, and mysteries which do not, even in principle. He notes that the cognitive capabilities of all organisms are limited by biology, e.g. a mouse will never speak. In the same way, certain problems may be beyond our understanding.

The term New Mysterianism has been extended by some writers to encompass the wider philosophical position that humans don't have the intellectual ability to understand many hard problems, not just the problem of consciousness, at a scientific level. This position is also known as Anti-Constructive Naturalism.

For example, in the mind-body problem, emergent materialism claims that humans aren't smart enough to determine "the relationship between mind and matter." [4] Strong agnosticism is a religious application of this position.

Colin McGinn is the leading proponent of the New Mysterian position.

Critics argue this philosophy isn't useful and encourages capitulation. One critic noted:

the extreme "Mysterian" position, that there are vital issues forever beyond our reach, is in many ways deeply unsatisfying. [7]

References

[1] McGinn, Colin - The Problem of Consciousness

[2] McGinn, Colin - Problems in Philosophy: the limits of enquiry

[3] McGinn, Colin - The Mysterious Flame

[4] Blackburn, Simon - Think: A compelling introduction to philosophy, chapter two

[5] Flanagan, Owen - The Science of the Mind (1991) 2ed MIT Press, Cambridge

[6] Horgan, John - The Undiscovered Mind (1999), Phoenix, ISBN 0753810980


text:
Movie Making Manual/Power Sources

On a film set, the power source is usually managed by the Electrical Department. Depending on where you are shooting and the volume of power the production requires, many different power sources are used. Typically you are either using Stage Power, House Power, A Tie-In, or a Generator.

Stage Power
When filming on a sound-stage large amounts of power are typically provided as part of the facility, although this is not always the case. Typically, power is provided in the form of 3-phase 110v with Cam-Lock hook-ups.

House Power
House power refers to power that is already installed within a location. For example, if you are shooting in a apartment, House Power refers to existing power installed in the apartment. House power is generally not preferred because: lighting equipment can require more power than is available, circuit-boxes can be difficult to locate in the event of a overload, a relatively large amount of power is usually used which increases the power-bill for that cycle.

Tie-ins
A Tie-In is a method of tapping directly into the power that feeds a building from the city power-grid, thereby bypassing the limits of the circuits that are installed in the building.

A Tie-In is a dangerous activity which requires experience and skill. Improper methods can result in damage to city power-grids and death.

Generator
Generators are used in Motion Picture Production to provide power to all the departments of the production, the most demanding on which is the lighting department. Typically generators are used when filming on location, as power is normally provided when filming on a sound-stage.

/Cinematography /Production

title: Movie Making Manual/Power Sources


text:
Movie Making Manual/Monitoring and Measuring Exposure

Using BW Polaroids to determine contrast value for film productions
Polaroids are a cost effective way to pre-visualize contrast values when shooting on film. The rush to proclaim Polaroid film dead is premature as Polaroid verification of film contrast can save a film shoot thousands of dollars by preventing costly lighting mistakes. Most Successful Directors of Photography have developed other means for checking exposure, however for second unit shoots it can be an excellent way to avoid costly mistakes. For low budget shoots where every dollar has already been squeezed, avoiding costly reshoots is a no brainer that the proper Polaroid set-up can help prevent.

Not just any polaroid camera will work however. Specially modified Polaroid 110B cameras are the polaroid of choice. These cameras use Polaroid 664 and 667 film.

External Link: Polaroid Examples

=Getting a video signal out of your camera=

Video taps for film cameras
Monitoring the image being recorded by a film camera requires that the film camera has been fitted with a 'video tap'. This is just a little camera which sits near the view finder. The image from these cameras is often of low quality and will flicker when the camera is rolling because the rotating shutter obscures the video tap's view.

Digital output from video cameras
=Monitors=

Cabling
If using coax connections then you must make sure the coax is properly terminated. Some monitors have internal termination but these frequently fail.

Monitoring on a CRT
The desire to obsolete CRT monitoring is partially economically driven since picture tube manufacturing has been reduced by many well known manufacturers, including Sony. However CRT monitoring is still recognized as one of the most accurate methods of monitoring when a waveform/vectorscope is not available. The desire to downsize the size of the monitor and move to a flatter screen with less backend protrusion has been the desire of location production for many years now, but this size reduction has also resulted in less reliable monitoring, especially of the black levels.

Monitoring on a laptop
For DV and, soon, for HD, it is possible to monitor on a laptop. The exact features are dependent on the software but it's usually possible to do the following things using a laptop hooked up to your camera whilst recording:

 * Record direct-to-disk
 * Monitor the exposure more closely using a virtual scope

Examples of software which allows you to monitor on a laptop

 * Serious Magic's DVrack
 * Canon's Console software

=Monitoring High Definition=

Consider doing location monitoring High Def. Ailed the problems of back focus associated to HD production, it's entirely possible that things can be soft, and then only spotted in the edit or later. Viewfinders are of course only wee monochrome monitors, and it's fraught with danger. Go for a 14" and have a 9" for those 'batt's only', establishing shot, exterior quickies, (plenty of light, long depth of field).

=Monitoring exposure= It's generally A Bad Idea to judge your exposure using just the view finder. There are several tools your can use to get a more accurate measure of your exposure:

Using zebra
Many modern DV cameras come with a zebra option. This creates a white and black stripe pattern over areas of the picture that are over-exposed, allowing one to adjust the aperture, shutter speed, gain, etc. until there is no over-exposure.

Using a 'scope to monitor exposure
A scope shows you detailed information about the exposure of each shot by displaying a waveform for each channel (RGB). http://en.wikipedia.org/wiki/Vectorscope To do: add pictures of scopes in action, write more details about how scopes help monitor exposure

Using a light meter
http://en.wikipedia.org/wiki/Light_meter

/Production /Cinematography /Post-production


text:
Template:Gmail

Overview — Introduction — Facts — Basics — Advanced — Last tips — Other

title: Template:Gmail


text:
Template:Rueda de Casino/Command

 * Pronunciation:
 * English:
 * Related commands:

Summary:

Description:

title: Template:Rueda de Casino/Command


text:
X86 Disassembly/Objects and Classes

Object-Oriented Programming
Object-Oriented (OO) programming provides for us a new unit of program structure to contend with: the Object. This chapter will look at disassembled classes from C++. This chapter will not deal directly with COM, but it will work to set a lot of the groundwork for future discussions in reversing COM components (Windows users only).

Classes
A basic class that has not inherited anything can be broken into two parts, the variables and the methods. The non-static variables are shoved into a simple data structure while the methods are compiled and called like every other function.

When you start adding in inheritance and polymorphism, things get a little more complicated. For the purposes of simplicity, the structure of an object will be described in terms of having no inheritance. At the end, however, inheritance and polymorphism will be covered.

Variables
All static variables defined in a class resides in the static region of memory for the entire duration of the application. Every other variable defined in the class is placed into a data structure known as an object. Typically when the constructor is called, the variables are placed into the object in sequential order, see Figure 1.

A:

B:

However, the compiler typically needs the variables to be separated into sizes that are multiples of a word (2 bytes) in order to locate them. Not all variables fit this requirement, namely char arrays; some unused bits might be used pad the variables so they meet this size requirement. This is illustrated in Figure 2.

A:

B:

In order for the application to access one of these object variables, an object pointer needs to be offset to find the desired variable. The offset of every variable is known by the compiler and written into the object code wherever it's needed. Figure 3 shows how to offset a pointer to retrieve variables.

Figure 3: This shows how to offset a pointer to retrieve variables. The first line places the address of variable 'a' into eax. The second line places the address of variable 'b' into ebx. And the last line places the variable 'c' into ecx.

Methods
At a low level, there is almost no difference between a function and a method. When decompiling, it can sometimes be hard to tell a difference between the two. They both reside in the text memory space, and both are called the same way. An example of how a method is called can be seen in Figure 4.

A:

B:

A notable characteristic in a method call is the address of the object being passed in as an argument. This, however, is not a always a good indicator. Figure 5 shows function with the first argument being an object passed in by reference. The result is function that looks identical to a method call.

A:

B:

Inheritance & Polymorphism
Inheritance and polymorphism completely changes the structure of a class, the object no longer contains just variables, they also contain pointers to the inherited methods. This is due to the fact that polymorphism requires the address of a method or inner object to be figured out at runtime.

Take Figure 6 into consideration. How does the application know to call D::one or C::one? The answer is that the compiler figures out a convention in which to order variables and method pointers inside the object such that when they're referenced, the offsets are the same for any object that has inherited its methods and variables.

Figure 6: A small C++ polymorphic loop that calls a function, one. The classes C and D both inherit an abstract class, A. The class A, for this code to work, must have a virtual method with the name, "one."

The abstract class A acts as a blueprint for the compiler, defining an expected structure for any class that inherits it. Every variable defined in class A and every virtual method defined in A will have the exact same offset for any of its children. Figure 7 declares a possible inheritance scheme as well as it structure in memory. Notice how the offset to C::one is the same as D::one, and the offset to C's copy of A::a is the same as D's copy. In this, our polymorphic loop can just iterate through the array of pointers and know exactly where to find each method.

A:

B:

title: X86 Disassembly/Objects and Classes


text:
X86 Disassembly/Variables

Variables
We've already seen some mechanisms to create local storage on the stack. This chapter will talk about some other variables, including global variables, static variables, variables labelled "const," "register," and "volatile." It will also consider some general techniques concerning variables, including accessor and setter methods (to borrow from object-oriented terminology). This section may also talk about setting memory breakpoints in a debugger to track memory I/O on a variable.

How to Spot a Variable
Variables come in 2 distinct flavors: those that are created on the stack (local variables), and those that are accessed via a hardcoded memory address (global variables). Any memory that is accessed via a hard-coded address is usually a global variable. Variables that are accessed as an offset from esp, or ebp are frequently local variables.

 * Hardcoded address : Anything hardcoded is a value that is stored as-is in the binary, and is not changed at runtime. For instance, the value 0x2054 is hardcoded, whereas the current value of variable X is not hard-coded and may change at runtime.

Example of a hardcoded address:

OR:

Example of a non-hardcoded (softcoded?) address:

In the last example, the value of ecx is calculated at run-time, whereas in the first 2 examples, the value is the same every time. RVAs are considered hard-coded addresses, even though the loader needs to "fix them up" to point to the correct locations.

.BSS and .DATA sections
Both .bss and .data sections contain values which can change at run-time (e.g. variables). Typically, variables that are initialized to a non-zero value in the source are allocated in the .data section (e.g. "int a = 10;"). Variables that are not initialized, or initialized with a zero value, can be allocated to the .bss section (e.g. "int arr[100];"). Because all values of .bss variables are guaranteed to be zero at the start of the program, there is no need for the linker to allocate space in the binary file. Therefore, .bss sections do not take space in the binary file, regardless of their size.

"Static" Local Variables
Local variables labeled static maintain their value across function calls, and therefore cannot be created on the stack like other local variables are. How are static variables created? Let's take a simple example C function:

Compiling to a listing file with cl.exe gives us the following code:

Normally when assembly listings are posted in this wikibook, most of the code gibberish is discarded to aid readability, but in this instance, the "gibberish" contains the answer we are looking for. As can be clearly seen, this function creates a standard stack frame, and it doesn't create any local variables on the stack. In the interests of being complete, we will take baby-steps here, and work to the conclusion logically.

In the code for Line 7, there is a call to _printf with 3 arguments. Printf is a standard libc function, and it therefore can be assumed to be cdecl calling convention. Arguments are pushed, therefore, from right to left. Three arguments are pushed onto the stack before _printf is called:

The second one, _a$[ebp] is partially defined in this assembly instruction:

_a$ = 8

And therefore _a$[ebp] is the variable located at offset +8 from ebp, or the first argument to the function. OFFSET FLAT:$SG797 likewise is declared in the assembly listing as such:

If you have your ASCII table handy, you will notice that 0aH = 0x0A = '\n'. OFFSET FLAT:$SG797 then is the format string to our printf statement. Our last option then is the mysterious-looking "?x@?1??MyFunction@@9@9", which is defined in the following assembly code section:

This shows that the Microsoft C compiler creates static variables in the .bss section. This might not be the same for all compilers, but the lesson is the same: local static variables are created and used in a very similar, if not the exact same, manner as global values. In fact, as far as the reverser is concerned, the two are usually interchangeable. Remember, the only real difference between static variables and global variables is the idea of "scope", which is only used by the compiler.

Signed and Unsigned Variables
Integer formatted variables, such as int, char, short and long may be declared signed or unsigned variables in the C source code. There are two differences in how these variables are treated:
 * 1) Signed variables use signed instructions such as add, and sub. Unsigned variables use unsigned arithmetic instructions such as addi, and subi.
 * 2) Signed variables use signed branch instructions such as jge and jl. Unsigned variables use unsigned branch instructions such as jae, and jb.

The difference between signed and unsigned instructions is the conditions under which the various flags for greater-than or less-than (overflow flags) are set. The integer result values are exactly the same for both signed and unsigned data.

Floating-Point Values
Floating point values tend to be 32-bit data values (for float) or 64-bit data values (for double). These values are distinguished from ordinary integer-valued variables because they are used with floating-point instructions. Floating point instructions typically start with the letter f. For instance, fadd, fcmp, and similar instructions are used with floating point values. Of particular note are the fload instruction and variants. These instructions take an integer-valued variable and converts it into a floating point variable.

We will discuss floating point variables in more detail in a later chapter.

Global Variables
Global variables do not have a limited scope like lexical variables do inside a function body. Since the notion of lexical scope implies the use of the system stack, and since global variables are not lexical in nature, they are typically not found on the stack. Global variables tend to exist in the program as a hard-coded memory address, a location which never changes throughout program execution. These could exist in the DATA segment of the executable, or anywhere else that a hard-coded memory address can be used to store data.

In C, global variables are defined outside the body of any function. There is no "global" keyword. Any variable which is not defined inside a function is global. In C however, a variable which is not defined inside a function is only global to the particular source code file in which it is defined. For example, we have two files  and , and a global variable  :

In the example above, the variable  is visible inside the file , but is not visible inside the file. To make  visible inside all project files, we need to use the   keyword, which we will discuss below.

" " Variables
The C programming language specifies a special keyword " " to define variables which are lexical to the function (they cannot be referenced from outside the function) but they maintain their values across function calls. Unlike ordinary lexical variables which are created on the stack when the function is entered and are destroyed from the stack when the function returns, static variables are created once and are never destroyed.

Static variables in C are global variables, except the compiler takes precautions to prevent the variable from being accessed outside of the parent function's scope. Like global variables, static variables are referenced using a hardcoded memory address, not a location on the stack like ordinary variables. However unlike globals, static variables are only used inside a single function. There is no difference between a global variable which is only used in a single function, and a static variable inside that same function. However, it's good programming practice to limit the number of global variables, so when disassembling, you should prefer interpreting these variables as static instead of global.

" " Variables
The  keyword is used by a C compiler to indicate that a particular variable is global to the entire project, not just to a single source code file. Besides this distinction, and the slightly larger lexical scope of extern variables, they should be treated like ordinary global variables.

In static libraries, variables marked as being extern might be available for use with programs which are linked to the library.

Global Variables Summary
Here is a table to summarize some points about global variables:

When disassembling, a hard-coded memory address should be considered to be an ordinary global variable unless you can determine from the scope of the variable that it is static or extern.

Constants
Variables qualified with the const keyword (in C) are frequently stored in the .data section of the executable. Constant values can be distinguished because they are initialized at the beginning of the program, and are never modified by the program itself. For this reasons, some compilers may choose to store constant variables (especially strings) in the .text section of the executable, thus allowing the sharing of these variables across multiple instances of the same process. This creates a big problem for the reverser, who now has to decide whether the code he's looking at is part of a constant variable or part of a subroutine.

"Volatile" memory
In C and C++, variables can be declared "volatile," which tells the compiler that the memory location can be accessed from external or concurrent processes, and that the compiler should not perform any optimizations on the variable. For instance, if multiple threads were all accessing and modifying a single global value, it would be bad for the compiler to store that variable in a register sometimes, and flush it to memory infrequently. In general, Volatile memory must be flushed to memory after every calculation, to ensure that the most current version of the data is in memory when other processes come to look for it.

It is not always possible to determine from a disassembly listing whether a given variable is a volatile variable. However, if the variable is accessed frequently from memory, and its value is constantly updated in memory (especially if there are free registers available), that's a good hint that the variable might be volatile.

Simple Accessor Methods
An Accessor Method is a tool derived from OO theory and practice. In its most simple form, an accessor method is a function that receives no parameters (or perhaps simply an offset), and returns the value of a variable. Accessor and Setter methods are ways to restrict access to certain variables. The only standard way to get the value of the variable is to use the Accessor.

Accessors can prevent some simple problems, such as out-of-bounds array indexing, and using uninitialized data. Frequently, Accessors contain little or no error-checking.

Here is an example:

Because they are so simple, accessor methods are frequently heavily optimized (they generally don't need a stack frame), and are even occasionally inlined by the compiler.

Simple Setter (Manipulator) Methods
Setter methods are the antithesis of an accessor method, and provide a unified way of altering the value of a given variable. Setter methods will often take as a parameter the value to be set to the variable, although some methods (Initializers) simply set the variable to a pre-defined value. Setter methods often do bounds checking, and error checking on the variable before it is set, and frequently either a) return no value, or b) return a simple boolean value to determine success.

Here is an example:

title: X86 Disassembly/Variables


text:
X86 Disassembly/Data Structures

Data Structures
Few programs can work by using simple memory storage; most need to utilize complex data objects, including pointers, arrays, structures, and other complicated types. This chapter will talk about how compilers implement complex data objects, and how the reverser can identify these objects.

Arrays
Arrays are simply a storage scheme for multiple data objects of the same type. Data objects are stored sequentially, often as an offset from a pointer to the beginning of the array. Consider the following C code:

Which is identical to the following asm code:

Now, consider the following example:

This (roughly) translates into the following asm pseudo-code:

The entire array is created on the stack, and the pointer to the bottom of the array is stored in the variable "array". An optimizing compiler could ignore the last instruction, and simply refer to the array via a +0 offset from esp (in this example), but we will do things verbosely.

Likewise, consider the following example:

This will translate into the following asm pseudo-code:

Which looks harmless enough. But, what if a program inadvertantly accesses buffer[4]? what about buffer[5]? what about buffer[8]? This is the makings of a buffer overflow vulnerability, and (might) will be discussed in a later section. However, this section won't talk about security issues, and instead will focus only on data structures.

Spotting an Array on the Stack
To spot an array on the stack, look for large amounts of local storage allocated on the stack ("sub esp, 1000", for example), and look for large portions of that data being accessed by an offset from a different register from esp. For instance:

is a good sign of an array being created on the stack. Granted, an optimizing compiler might just want to offset from esp instead, so you will need to be careful.

Spotting an Array in Memory
Arrays in memory, such as global arrays, or arrays which have initial data (remember, initialized data is created in the .data section in memory) and will be accessed as offsets from a hardcoded address in memory:

It needs to be kept in mind that structures and classes might be accessed in a similar manner, so the reverser needs to remember that all the data objects in an array are of the same type, that they are sequential, and they will often be handled in a loop of some sort. Also, (and this might be the most important part), each elements in an array may be accessed by a variable offset from the base.

Since most times an array is accessed through a computed index, not through a constant, the compiler will likely use the following to access an element of the array:

If the array holds elements larger than 1 byte (for char), the index will need to be multiplied by the size of the element, yielding code similar to the following:

This pattern can be used to distinguish between accesses to arrays and accesses to structure data members.

Structures
All C programmers are going to be familiar with the following syntax:

It's called a structure (Pascal programmers may know a similar concept as a "record").

Structures may be very big or very small, and they may contain all sorts of different data. Structures may look very similar to arrays in memory, but a few key points need to be remembered: structures do not need to contain data fields of all the same type, structure fields are often 4-byte aligned (not sequential), and each element in a structure has its own offset. It therefore makes no sense to reference a structure element by a variable offset from the base.

Take a look at the following structure definition:

Assuming the pointer to the base of this structure is loaded into ebx, we can access these members in one of two schemes:

The first arrangement is the most common, but it clearly leaves open an entire memory word (2 bytes) at offset +6, which is not used at all. Compilers occasionally allow the programmer to manually specify the offset of each data member, but this isn't always the case. The second example also has the benefit that the reverser can easily identify that each data member in the structure is a different size.

Consider now the following function:

The function clearly takes a pointer to a data structure as its first argument. Also, each data member is the same size (4 bytes), so how can we tell if this is an array or a structure? To answer that question, we need to remember one important distinction between structures and arrays: the elements in an array are all of the same type, the elements in a structure do not need to be the same type. Given that rule, it is clear that one of the elements in this structure is a pointer (it points to the base of the structure itself!) and the other two fields are loaded with the hex value 0x0A (10 in decimal), which is certainly not a valid pointer on any system I have ever used. We can then partially recreate the structure and the function code below:

As a quick aside note, notice that this function doesn't load anything into eax, and therefore it doesn't return a value.

Advanced Structures
Lets say we have the following situation in a function:

what is happening here? First, esi is loaded with the value of the function's first parameter (ebp + 8). Then, ecx is loaded with a pointer to the offset +8 from esi. It looks like we have 2 pointers accessing the same data structure!

The function in question could easily be one of the following 2 prototypes:

one pointer offset from another pointer in a structure often means a complex data structure. There are far too many combinations of structures and arrays, however, so this wikibook will not spend too much time on this subject.

Identifying Structs and Arrays
Array elements and structure fields are both accessed as offsets from the array/structure pointer. When disassembling, how do we tell these data structures apart? Here are some pointers:

 * 1) Array elements are not meant to be accessed individually. Array elements are typically accessed using a variable offset
 * 2) Arrays are frequently accessed in a loop. Because arrays typically hold a series of similar data items, the best way to access them all is usually a loop. Specifically,  style loops are often used to access arrays, although there can be others.
 * 3) All the elements in an array have the same data type.
 * 4) Struct fields are typically accessed using constant offsets.
 * 5) Struct fields are typically not accessed in order, and are also not accessed using loops.
 * 6) Struct fields are not typically all the same data type, or the same data width

Linked Lists and Binary Trees
Two common structures used when programming are linked lists and binary trees. These two structures in turn can be made more complicated in a number of ways. Shown in the images below are examples of a linked list structure and a binary tree structure.

Each node in a linked list or a binary tree contains some amount of data, and a pointer (or pointers) to other nodes. Consider the following asm code example:

At each loop iteration, a data value at [ebp + 0] is compared with the value 10. If the two are equal, the loop is ended. If the two are not equal, however, the pointer in ebp is updated with a pointer at an offset from ebp, and the loop is continued. This is a classic linked-loop search technique. This is analagous to the following C code:

Binary trees are the same, except two different pointers will be used (the right and left branch pointers).

title: X86 Disassembly/Data Structures


text:
X86 Disassembly/Branches

Branching
Computer science professors tell their students to avoid jumps and goto instructions, to avoid the proverbial "spaghetti code." Unfortunately, assembly only has jump instructions to control program flow. This chapter will explore the subject that many people avoid like the plague, and will attempt to show how the spaghetti of assembly can be translated into the more familiar control structures of high-level language. Specifically, this chapter will focus on If-Then-Else and Switch branching instructions.

If-Then
Let's consider a generic if statement in pseudo-code followed by its equivalent form using jumps:

What does this code do? In English, the code checks the condition and performs a jump only if it is false. With that in mind, let's compare some actual C code and its Assembly translation:

Note that when we translate to assembly, we need to negate the condition of the jump because--like we said above--we only jump if the condition is false. To recreate the high-level code, simply negate the condition once again.

Negating a comparison may be tricky if you're not paying attention. Here are the correct dual forms:

And here are some examples.

Is produced by these C statements:

As you can see, x is incremented only if it is less than or equal to y. Thus, if it is greater than y, it will not be incremented as in the assembler code. Similarly, the C code

produces this assembler code:

X is incremented in the C code only if it is less than y, so the assembler code now jumps if it's greater than or equal to y. This kind of thing takes practice, so we will try to include lots of examples in this section.

If-Then-Else
Let us now look at a more complicated case: the If-Then-Else instruction.

Now, what happens here? Like before, the if statement only jumps to the else clause when the condition is false. However, we must also install an unconditional jump at the end of the "then" clause, so we don't perform the else clause directly afterwards.

Now, here is an example of a real C If-Then-Else:

Which gets translated into the following assembly code:

As you can see, the addition of a single unconditional jump can add an entire extra option to our conditional.

Switch-Case
Switch-Case structures can be very complicated when viewed in assembly language, so we will examine a few examples. First, keep in mind that in C, there are several keywords that are commonly used in a switch statement. Here is a recap:

 * Switch : This keyword tests the argument, and starts the switch structure
 * Case : This creates a label that execution will switch to, depending on the value of the argument.
 * Break : This statement jumps to the end of the switch block
 * Default : This is the label that execution jumps to if and only if it doesn't match up to any other conditions

Lets say we have a general switch statement, but with an extra label at the end, as such:

Now, every break statement will be immediately replaced with the statement

But what do the rest of the statements get changed to? The case statements can each resolve to any number of arbitrary integer values. How do we test for that? The answer is that we use a "Switch Table". Here is a simple, C example:

And when we compile this with cl.exe, we can generate the following listing file:

Lets work our way through this. First, we see that line 10 sets up our standard stack frame, and it also saves ecx. Why does it save ecx? Scanning through the function, we never see a corresponding "pop ecx" instruction, so it seems that the value is never restored at all. In fact, the compiler isn't saving ecx at all, but is instead simply reserving space on the stack: it's creating a local variable. The original C code didn't have any local variables, however, so perhaps the compiler just needed some extra scratch space to store intermediate values. Why doesn't the compiler execute the more familiar "sub esp, 4" command to create the local variable? push ecx is just a faster instruction that does the same thing. This "scratch space" is being referenced by a negative offset from ebp. tv64 was defined in the beginning of the listing as having the value -4, so every call to "tv64[ebp]" is a call to this scratch space.

There are a few things that we need to notice about the function in general:

 * Label $L803 is the end_of_switch label. Therefore, every "jmp SHORT $L803" statement is a break. This is verifiable by comparing with the C code line-by-line.
 * Label $L818 contains a list of hard-coded memory addresses, which here are labels in the code section! Remember, labels resolve to the memory address of the instruction. This must be an important part of our puzzle.

To solve this puzzle, we will take an in-depth look at line 11:

This sequence performs the following pseudo-C operation:

if( argc - 1 >= 4 ) {   goto $L810;   /* the default */ } label *L818[] = { $L806, $L807, $L808, $L809 }; /* define a table of jumps, one per each case */ // goto L818[argc - 1];  /* use the address from the table to jump to the correct case */

Here's why...

The Setup
The value of argc is moved into eax. The value of eax is then immediately moved to the scratch space. The value of the scratch space is then moved into ecx. Sounds like an awfully convoluted way to get the same value into so many different locations, but remember: I turned off the optimizations. The value of ecx is then decremented by 1. Why didn't the compiler use a dec instruction instead? Perhaps the statement is a general statement, that in this case just happens to have an argument of 1. We don't know why exactly, all we know is this:

 * eax = "scratch pad"
 * ecx = eax - 1

Finally, the last line moves the new, decremented value of ecx back into the scratch pad. Very inefficient.

The Compare and Jumps
The value of the scratch pad is compared with the value 3, and if the unsigned value is above 3 (4 or more), execution jumps to label $L810. How do I know the value is unsigned? I know because ja is an unsigned conditional jump. Let's look back at the original C code switch:

Remember, the scratch pad contains the value (argc - 1), which means that this condition is only triggered when argc > 4. What happens when argc is greater than 4? The function goes to the default condition. Now, let's look at the next two lines:

edx gets the value of the scratch pad (argc - 1), and then there is a very weird jump that takes place: execution jumps to a location pointed to by the value (edx * 4 + $L818). What is $L818? We will examine that right now.

The Switch Table
$L818 is a pointer, in the code section, to a list of other code section pointers. These pointers are all 32bit values (DD is a DWORD). Let's look back at our jump statement:

In this jump, $L818 isn't the offset, it's the base, edx*4 is the offset. As we said earlier, edx contains the value of (argc - 1). If argc == 1, we jump to [$L818 + 0] which is $L806. If argc == 2, we jump to [$L818 + 4], which is $L807. Get the picture? A quick look at labels $L806, $L807, $L808, and $L809 shows us exactly what we expect to see: the bodies of the case statements from the original C code, above. Each one of the case statements calls the function "MyFunction", then breaks, and then jumps to the end of the switch block.

Ternary Operator ?:
Again, the best way to learn is by doing. Therefore we will go through a mini example to explain the ternary operator. Consider the following C code program:

cl.exe produces the following assembly listing file:

Line 2 sets up a stack frame, and line 4 is a standard exit sequence. There are no local variables. It is clear that Line 3 is where we want to look.

The instruction "xor eax, eax" simply sets eax to 0. For more information on that line, see the chapter on unintuitive instructions. The cmp instruction tests the condition of the ternary operator. The setle function is one of a set of x86 functions that works like a conditional move: al gets the value 1 if argc <= 1. Isn't that the exact opposite of what we wanted? In this case, it is. Let's look at what happens when argc = 0: al gets the value 1. al is decremented (al = 0), and then eax is logically anded with 5. 5 & 0 = 0. When argc == 2 (greater than 1), the setle instruction doesn't do anything, and eax still is zero. eax is then decremented, which means that eax == -1. What is -1?

In x86 processors, negative numbers are stored in two's-complement format. For instance, let's look at the following C code:

At the end of this C code, x will have the value 11111111: all ones!

When argc is greater than 1, setle sets al to zero. Decrementing this value sets every bit in eax to a logical 1. Now, when we perform the logical and function we get:

...11111111 &...00000101    ;101 is 5 in binary ...00000101

eax gets the value 5. In this case, it's a roundabout method of doing it, but as a reverser, this is the stuff you need to worry about.

For reference, here is the GCC assembly output of the same ternary operator from above:

Notice that GCC produces slightly different code than cl.exe produces. However, the stack frame is set up the same way. Notice also that GCC doesn't give us line numbers, or other hints in the code. The ternary operator line occurs after the instruction "call __main". Let's highlight that section here:

Again, xor is used to set edx to 0 quickly. Argc is tested against 2 (instead of 1), and dl is set if argc is greater then or equal. If dl gets set to 1, the leal instruction directly thereafter will move the value of 5 into eax (because lea (edx,edx,4) means edx + edx * 4, i.e. edx * 5).

title: X86 Disassembly/Branches