paulgorman.org

< ^ txt

Sun Jan 17 06:00:01 EST 2021 ======================================== Slept from one to eight. Cloudy. Chance of snow showers early in the morning. Snow showers early in the evening. Accumulations up to half an inch. Highs in the mid 30s. West winds 5 to 10 mph. Chance of snow 90 percent. Washed dishes. Watched some anime. Still trying to learn C better. My difficulties, no doubt in large part, come from my casual approach. But, even so, I find the explanations given by various tutorials give about how C understands values and types lacking. I suspect most of the tutorials over-simplify based on the assumption that readers will pick up the real details in other sources or by experimentation. K&R is excellent, but unfortunately I find it excrutiatingly dull; when I do several of the excercises, I always learn something, but I just can focus on many of them. What follows are my suppositions about how C values and types work, much of which will certainly be wrong. Just writing through it for myself here. Values are either scalar values or aggregate values. (And, arguably, pointers are a third type. And functions are another type, but whatever.) The important difference is that C understands scalar values as just a starting memory address and a length. Type is synonymous with length. Integers and characters are scalar types. Aggregate values can't be completely described by a starting memory address and a length. An array of chars is an aggregate type. The array of chars has a starting memory address and a type that specifies the length of the first value, but C doesn't store the length of the array(?). The programmer has to watch for the end of the array, and take care to not overrun it. Aggregate types are terminated (maybe?) by a zero-value of the type. That why we say C string are null terminated. Pointers hold two facts: a memory address (e.g., a 64-bit integer on 64-bit platforms) and a type for the value at that address. So, char, short, int, long, long, float, and double are C's basic scalar types. Each of these scalar types has a corresponding pointer type (e.g., char pointers, int pointers, etc.). C's aggregate types are structs and arrays. Servings: grains 4/6, fruit 1/4, vegetables 3/4, dairy 4/2, meat 0/3, nuts 0.5/0.5 Brunch: potato chips, banana Lunch: broccoli, coffee Dinner: nachos

< ^ txt