CSC161 2011S Imperative Problem Solving

Reading: Types and Operators (1)

Reading: K&R 2.1-2.6. Also GNU Coding Standards, 5.1-5.4

Please submit a question by 9 p.m. on Tuesday, 1 February 2011.


This may be an incredibly stupid question...but what does foo mean?

It is not a stupid question. I'll give the etymology in class.

Can we review section .1 of the K&R reading? It confused me.

That's a bit too vague to answer. 1.1 or 2.1. What confused you?

Just a question abut the formatting of source code. Will there be points docked if it looks...messy? Sometimes things are changed sporadically to make a set of code work, and it ends up looking very...wild.

You have a responsibility to format your code so that it reads cleanly. That's why I asked you to read the coding standards.


Coding Standards

Why is it not okay to do the assignment then evaluate thing in an if test, but it's okay to do it in a while test? (Last bit of 5.3) When you do it in a while loop, won't it effectively be a if in the underlying bit, therefore why don't we like it?

For many common situations (such as the file processing examples we've already seen), it's hard to write concise while loops without doing an assignment in the test. For conditionals, on the other hand, it's usually no more difficult to separate out the assignment.

It is stated that, When you want to define names with constant integer values, use enum rather than #define. in section 5.4 of coding standards. Why?

We use #define for a variety of tasks. By using enum, we clarify that we're defining these things as values in a group and therefore help the reader.

Why do we try to avoid having two operators of different precedence at the same level of indentation?

It confuses the reader.

So when they say using underscores to make names easier to read, it functions like a comma if there was a list of names?

No! It ties things together into a single word. It's intended for things like theprofsname, which is much more readable as the_profs_name.


Is the double type just a more precise version of float?

Yes.

What exactly is the value of an "unsigned" number?

Unsigned numbers range from 0 to some upper bound. We'll discuss the particular bounds in a week or two.

What are the correct usages of "=" and "==" ? I understand that "==" is equal to but what is the "=" doing then? What about when there is such things as n=1?

The double equals sign checks for equalty. I tend to read it as is. The single equals sign is used to store values in variables. I tend to read it as becomes or gets.

What are the uses of octal and hex, and how do they compare to binary?

I don't understand the correlation between octal, hexadecimal and decimal integers. How can the decimal 31 be expressed as 037 and 0X1F?

Different bases. We'll go over them in class.

When would const be helpful, instead of just putting the constant itself in there? Or why not put things that you want to be constant in a program that just does not change it?

If you define a constant, you can change what the constant is without having to read through your program to figure out what uses of a particular number have certain meanings.

What is meant when it is said that shorts are 16 bits and longs are 32 bits and what is the advantage of declaring a number to be one of the two (why not just call it an int)? Why can short and long only apply to integers?

Didn't I answer this on a previous Q&A?

Since quotation marks are used to delimit character strings, how is the quotation mark represented if you want to print it?

You prefix it with a backslash.

How is it that in the modulo operator explanation in R&K dividing a year by 400 makes a year a leap year?

There's a funny rule that years divisible by 100 are not leap years, unless they also happen to be divisible by 400.

What is the difference between /* .... */ and // notations?

We tend to use the /* ... */ notation for multi-line comments and the // notation for single-line comments.

What do they mean by single-precision or double-precision floating point?

Floating-point numbers are a representation of real numbers which we will cover in a week or two. Double-precisio floating point numbers provide a more accurate representation.


What is a defun? (from gnu coding standards)

The LISP version of Scheme's define.

What is the significance of 16 vs. 32 bit systems? What is the book saying about 16 vs. 32 bits? Is this outdated now that Windows 7 has a 64 bit version?

Somewhat related: Why does Internet Explorer 64-bit sometimes function differently than the default IE in Windows 7? What do Firefox, Chrome, and Safari use and why?

I noticed that underscores are supposed used in place of other methods of separating words in a name (like camelcase; what I'm used to) because of how Emacs word commands interact with them. What kind of commands make this relevant, and why was Emacs developed to follow this convention/what made this convention practical?


The reading on the rules for C programming talked about using enum to name variables, but it did not mention how to name procedures. How could you go about doing that?

What is a D-bus interface?

Was it written this way to show it's similar to Scheme where we need to use the parenthesis in the right places?

mode = (inmode[j] == VOIDmode
        || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])
        ? outmode[j] : inmode[j]);

Why was there a need to create both signed and unsigned char variables and which ones are more commonly used?

I have understood what long double and float and everything does but I do not get how and when I would use any of them and when it makes a difference if I use one or the other.

What makes the capital and lowercase different? I understand that in terminal, if I'm trying to autocomplete a file, I can press TAB, but if it's in the wrong case, it won't complete it.

The GNU coding standards reading makes mention of a time when you need to alter your code so Emacs won't change it. Would this change come when you compile, when you save, or some other time? (sorry for the lateness, I didn't have time to begin the reading until I got off work at 9).

How does const differ from #define?

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Fri Feb 4 16:28:08 2011.
The source to the document was last modified on Fri Feb 4 16:28:07 2011.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2011S/Readings/c-types-ops-1.html.

Samuel A. Rebelsky, rebelsky@grinnell.edu