Monthly Archives: May 2008

From the Yellow Notepad: C

Amazon.com - A Book on C Here are a few notes from the yellow notepad I’ve been using for school over the last six months. This first installment touches on C. Later I’ll add some UNIX programming and C++ notes. Basically these are the things that struck me as I was quickly reading the “refresher” material for my spring class: “Advanced C Programming for UNIX.” After more than a decade with C, I feel I know the core language pretty well; and here are the things that struck me as worth noting.

Is there a portable way to refer precisely to datatypes of a particular size? Yes, in C99 #include <stdint.h>.

Use signed integer types larger than char with getc() or getchar() to accomodate EOF (-1).

A good running average is avg += (x - avg) / n; It reduces the chance of overflow, is fast, and doesn’t require you to keep track of all values.

Each comment collapses to a single blank character during parsing.

Many system names start with an underscore ( “_” ). Avoid creating new identifiers that start that way.

All functions have extern storage, just like variables defined outside of a function.

Use volatile when it’s possible that the variable’s value will change from outside the normal flow of control. Technically this prevents compiler and processor instruction reordering optimizations around the use of the variable.

The register storage class is for small, fast-changing variables like loop indices (not for bigger things like arrays). And you can’t do &variable for register-declared storage.

Array names are const pointers, so an array name is not a valid l-value.

It’s not possible to take an address of a literal value, like 3.14 or "I am the very model of a modern major general.". So . . .

Because C-strings are either arrays (char s[]) or pointers to memory areas (char *s), it’s illegal to reassign a value to a string variable directly (e.g., s = "new string"; /* won't compile */).

When passing multidimensional arrays to a function, the function’s argument list must give the size of all but the slowest changing dimension.

Function pointers: int (*f)(int, double) is the same as int f(int, double). The parentheses are necessary to ensure the * binds to f and not int. To use the function pointer f either of these is acceptable: (*f)(37, 3.14) or f(37, 3.14). (This is “declaration follows usage.”)

const int *p is a pointer to a constant int.
int const *p is a constant pointer to an int.

“LP64″ scheme means long ints and pointers are 64-bit values.

Some compilers use precompiled headers to speed up compilation. This can make the inclusion order of header files significant. Also, some compilers (like Xcode) use “prefix headers,” which are always included in a project.

Defining NDEBUG turns the assert() macro into a no-op.

Posted in C, Computing, From the Yellow Notepad, Software Engineering | 2 Comments

Memorial Day

If you’re in the U.S., I hope you enjoyed your Memorial Day.

Lisa and I went to the Old Burial Hill in Marblehead today, where Lisa took this picture:

In Memory of James Dennis Hammond
He was one of the Heroes of the Frigate Constitution and having been wounded in the capture of the Java he received a pension from his grateful Country untill his decease which happened Oct. 24, 1840 at the age of ?4 years 10 mos. & 14 days.

Posted in Burying Grounds, This is who we are | Leave a comment

Traveling again

Greetings from the Pacific Northwest. I’m in Bellevue, Washington, taking Herb Sutter’s class, Effective Concurrency. Scott Meyers took the chair right behind me; and, yes, he still needs a haircut. Of course, so do I . . . but not quite so badly. I suspect that I’ll write something here in the coming week or so about what I’m learning.

I spent some time over the weekend with my in-laws in Portland, Oregon. It was wonderful seeing them. And their mischievous dog Penny finally stopped barking at me whenever I stood up by the time I left. The weather is quite beautiful out here, and Dave (my father-in-law) and I went out to the Columbia River Gorge.

A few pictures from this trip and from the last year appear below. They’re all from my mobile phone. One day, I’ll get myself a real digital camera. Maybe one day soon. . . .

Navigating the District (April 2007)
Navigating the District (April 2007)
Iowa (June 2007)
Iowa (June 2007)
On Spectacle Island (Aug. 2007)
On Spectacle Island (Aug. 2007)
Traveling light - Rochester (Sept. 2007)
Traveling light – Rochester (Sept. 2007)
End of the film industry at Kodak - Rochester (Sept. 2007)
End of the film industry at Kodak – Rochester (Sept. 2007)
The Farm (Oct. 2007)
The Farm (Oct. 2007)
HDF Workshop - Largo, Maryland (Nov. 2007)
HDF Workshop – Largo, Maryland (Nov. 2007)
Lucretia - D.C. (Nov. 2007)
Lucretia – D.C. (Nov. 2007)
Rural Free Delivery, Postal Museum - D.C. (Nov. 2007)
Rural Free Delivery, Postal Museum – D.C. (Nov. 2007)
The future of mail delivery, Postal Museum - D.C. (Nov. 2007)
The future of mail delivery, Postal Museum – D.C. (Nov. 2007)
Commuting - Baltimore (Nov. 2007)
Commuting – Baltimore (Nov. 2007)
So, I did this project at work . . . (Dec. 2007)
So, I did this project at work . . . (Dec. 2007)
My new camera - Massachusetts (Dec. 2007)
My new camera – Massachusetts (Dec. 2007)
On the Cape (Dec. 2007)
On the Cape (Dec. 2007)
At the Tech Museum - San Jose (Jan. 2008)
At the Tech Museum – San Jose (Jan. 2008)
Camera quality targets - San Jose (Jan. 2008)
Camera quality targets – San Jose (Jan. 2008)
Using MATLAB to test image quality - San Jose (Jan. 2008)
Using MATLAB to test image quality – San Jose (Jan. 2008)
Bikes - Davis (Jan. 2008)
Bikes – Davis (Jan. 2008)
My new suit of armor - San Francisco (Feb. 2008)
My new suit of armor – San Francisco (Feb. 2008)
Shoe envy - San Francisco (Feb. 2008)
Shoe envy – San Francisco (Feb. 2008)
The Golden Gate Bridge - San Francisco (Feb. 2008)
The Golden Gate Bridge – San Francisco (Feb. 2008)
Clean desk (April 2007)
Clean desk (April 2007)
Homai Vyarawala lecture - Cambridge (May 2008)
Homai Vyarawala lecture – Cambridge (May 2008)
Messy desk (May 2008)
Messy desk (May 2008)
Spring out my window - Natick (May 2008)
Spring out my window – Natick (May 2008)
Watching the Sox on the plane - Seattle (May 2008)
Watching the Sox on the plane – Seattle (May 2008)
Looking out at the Gorge #1 - Oregon (May 2008)
Looking out at the Gorge #1 – Oregon (May 2008)
Looking out at the Gorge #2 - Oregon (May 2008)
Looking out at the Gorge #2 – Oregon (May 2008)
Latourelle Falls - Oregon (May 2008)
Latourelle Falls – Oregon (May 2008)
Ready for learning - Bellevue (May 2008)
Ready for learning – Bellevue (May 2008)
Posted in Computing, Travel, USA | 1 Comment

Adding L* to RGBG

A few months ago I mentioned some research by Hultgren and Hertl about the quality of images from mobile devices, in which they discovered that mobile devices with small image sensors tend to perform very poorly in the circumstances where they are most used: indoors on close-up scenes. Camera-shake, image fuzziness, and large amounts of noise due to the low-light environment were among the top complaints.

It seems that Kodak may have an answer to the “low-light problem” by changing the sensor design in a subtle way. Remember that most digital cameras use a red-green-blue-green (RGBG) color filter array (CFA) over the sensor as a fundamental part of image formation. This “Bayer pattern” (named after another Kodak researcher) looks like this:


Kodak’s novel approach (used in their new TRUESENSE CMOS technology) adds clear gaps in the CFA pattern to increase the overall level of illumination striking the sensor:


There are some trade-offs in terms of color resolution, but the results are pretty impressive. Plus, Kodak is initially targetting the technology for small image sensors where resolution was never very good to begin with and the images stand to improve.

Posted in Fodder for Techno-weenies, Photography | Leave a comment

Central Artery Montage

It’s been a while since I posted any of my own photographs here — photos without headstones, that is. But today I installed Adobe Lightroom on the ‘ole PC, imported all of the old photos that I haven’t looked at in a while, and came across these composite photos from 2003.

I was going through a phase of making montages, inspired by a small series that Lisa made when we went to Sequoia National Park the year before. (I swear I didn’t know at the time that James Balog and David Hockney were doing this, too.) In early 2003, we still lived closer to Boston; and the old, rusty Central Artery was coming down as the Big Dig moved the highway underground. So I decided to spend an afternoon focusing on the old and new. (This was also the outing where I got detained by The Man.)

At the time, I was exploring the concept that photographs mediate experience in a completely artificial way, that they frame the world and construct experience, and that they’re essentially untrue. So I was purposefully not making my edges match or worrying too much about color constancy when I stitched them back together. Pointing out the unnaturalness of photographs was my goal. Moreover, the Artery always struck me as ugly, and I always felt disoriented when I was on or near it; I was trying to get that feeling across, too. Maybe it works, maybe it’s too “unpicturesque” or self-conscious — I’ll let you decide.

Central Artery Montage - Boston, MA

Central Artery Montage – Boston, MA (Click for larger . . .)

Central Artery Montage - Boston, MA

Central Artery Montage – Boston, MA (Click for larger . . .)

Central Artery Montage - Boston, MA

Central Artery Montage – Boston, MA (Click for larger . . .)

Posted in Commonwealth Project, Photography | 2 Comments

Security Vulnerability in CDF, plus a MATLAB Fix

The CDF folks at Goddard Space Flight Center have identified a security vulnerability — a buffer overflow to be specific — that can enable the execution of arbitrary code on your machine if you open a particular malformed file. If you’re accessing CDF files via MATLAB, you can download a security patch from NASA GSFC.

Thank you. That is all.

UPDATE: You can also download an update directly from The MathWorks.

Posted in Computing, File Formats, MATLAB | Leave a comment