🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Good C Interview questions?

#2087
From: Mark C. Orton
Date: Mon, 26 Feb 1996 22:14
31 lines
1490 bytes
Konrad Schwarz (schwarz@a3.complang.tuwien.ac.at) wrote:
: 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";

As long as you don't mind the trailing '\0' being appended to upmap,
that is.

: 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

However, it is bad for one reason:  If upmap is declared as upmap[]
(without specifying the size as 26), then sizeof upmap == 27.

--
Mark C. Orton
employed by (but not speaking for)
Pulse Communications, Inc.
Technical Details
Message-ID: <4gtbc5$agg@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4ggbns$86s@solutions.solon.com> <4gsabh$42o@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: marko@pulse.com (Mark C. Orton)
Newsgroups: comp.lang.c.moderated
Subject: Re: Good C Interview questions?
Date: 26 Feb 1996 16:14:28 -0600
Organization: Pulsecom
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4gtbc5$agg@solutions.solon.com>
References: <4ggbns$86s@solutions.solon.com> <4gsabh$42o@solutions.solon.com>
Reply-To: marko@pulse.com
NNTP-Posting-Host: solutions.solon.com
X-Newsreader: TIN [version 1.2 PL2]