🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Good C Interview questions?

#2092
From: msb
Date: Tue, 27 Feb 1996 01:02
25 lines
1388 bytes
> >       static const char upmap [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> ... 
> > by introducing upmap, we can now write
> > 	upmap [ expr % (sizeof upmap / sizeof *upmap) ]
> 
> [But if] upmap is declared as upmap[] (without specifying the
> size as 26), then sizeof upmap == 27.

Clashing features!  One could fix it this way:

	#define UPMAP "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	static const char upmap [sizeof UPMAP - 1] = UPMAP;
	#undef UPMAP
	...
	upmap [ expr % (sizeof upmap / sizeof *upmap) ]
	...

I no longer remember enough of the original context to know whether
the use of % is in fact safe and sensible here.
-- 
Mark Brader                     "A moment's thought would have shown him,
msb@sq.com                       but a moment is a long time and thought 
SoftQuad Inc., Toronto           is a painful process." -- A. E. Housman

My text in this article is in the public domain.
Technical Details
Message-ID: <4gtl6e$ciq@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4ggbns$86s@solutions.solon.com> <4gsabh$42o@solutions.solon.com> <4gtbc5$agg@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: msb@sq.com
Newsgroups: comp.lang.c.moderated
Subject: Re: Good C Interview questions?
Date: 26 Feb 1996 19:02:05 -0600
Organization: SoftQuad Inc., Toronto, Canada
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4gtl6e$ciq@solutions.solon.com>
References: <4ggbns$86s@solutions.solon.com> <4gsabh$42o@solutions.solon.com> <4gtbc5$agg@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com