🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2078

Re: Good C Interview questions?

#2078
From: Konrad Schwarz
Date: Mon, 26 Feb 1996 12:50
33 lines
1441 bytes
In article <4ggbns$86s@solutions.solon.com>, Lawrence Kirby writes:
|> This could be better written as:
|> 
|>      static const char upmap[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|> 

or even better as

      static const char upmap [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

Don't I just love to quibble!

but seriously: ``let your compiler do the walking''

The original posting also had code of the form
	"ABC...XYZ" [ expr % 26 ]

by introducing upmap, we can now write

	upmap [ expr % (sizeof upmap / sizeof *upmap) ]

which is good for two reasons:
	if we later change the length of the string, nothing breaks
	if we later change the type of upmap, nothing breaks

Change is localized; no additional identifiers are introduced.

Konrad Schwarz  

PS: The parenthesis are necessary above because multiplicative operators
associate from left to right.  Many people are unhappy with C's operators
because the precedence table is long; do you think think that associativity
is a problem too?
Technical Details
Message-ID: <4gsabh$42o@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4ggbns$86s@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: schwarz@a3.complang.tuwien.ac.at (Konrad Schwarz)
Newsgroups: comp.lang.c.moderated
Subject: Re: Good C Interview questions?
Date: 26 Feb 1996 06:50:57 -0600
Organization: TU Wien
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4gsabh$42o@solutions.solon.com>
References: <4ggbns$86s@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com