Questions about K&R (Kernighan and Ritchi)

S

spinoza1111

Keith:

I understand your feelings about not feeding trolls and generally I
sympathize. But in this instance you must see my point of view: There are
non-Americans who read this group, and they could easily get the
impression that Kenny and Nilges speak for mainstream America. It's
important that patriots like you and I speak up, and tell the world loud
and clear that America is still a great nation under God, a land of
freedom, free enterprise, and hope.

Thanks to the British, Hong Kong has especially some political and
maximal economic freedom. Powerful taipans have too much power, but in
America, the Constitution still gives rural states too much
representation in the makeup of the Senate. This is why unprincipled
political entrepeneurs can exploit Tea Baggery in rural communities.
The majority in the urban states are under-represented.

And, to keep the focus at least on programming and C: Open Source as a
form of virtual slave labor destroys opportunities for Free Labor,
which is what the Republican party under Lincoln fought for in the
Civil War.
 
S

spinoza1111

It may be important, but:

1.  This isn't the right group.
2.  Your political views are just as ridiculous and ill-founded as
theirs.
3.  You don't speak for "mainstream America" -- you just speak for the
other group of lunatics.

I know it's really hard to accept that we elected a black guy, but face it,

It must be, Peter, it must be. And Obama paid his academic dues; he
majored in politics and took law. You did not in the field you
profess, because you expected a free pass. Hurts, doesn't it?

Your Mom wants to destroy the chance for another Obama to emerge out
of Oakland so that white kids can skip science classes. Objectively,
this is racism.

Your treatment of Schildt and myself is isomorphic to the way in which
the Tea Baggers spread their rumors. Your views about C are isomorphic
to racism, since you use "shibboleth" instead of learning your trade.

Bill Howarth of Princeton's English department explained "shibboleth"
to me after I'd developed a Hypercard "stack" for him to use to
display poetry in literature class. Where, in "A Refusal to Mourn the
Death, by Fire, of a Child in London", Dylan Thomas refuses "the
shibboleth of the ear of corn", he's referring to the original Hebrew
meaning in which friend and foe were told apart by the way they said
"ear of corn".

Of course, this might be necessary in a tribal society. But it's
barbaric in programming to read a couple of lines, find a void main(),
and then say "this guy is a moron". It's like racism, in which even
people who profess not to be Tea Baggers still assume things based on
the shibboleth of skin color, or a Microsoft background.


it happened.  It isn't the end of the world.  Maybe the news hasn't reached
your part of "mainstream" America, yet, but it turns out black people got
the vote a while back and are now allowed to run for public office, even if
there's a die-hard minority of credulous fools willing to believe badly
photoshopped "evidence" that they aren't.  Please stop claiming to represent
America.

But he does represent you. You're the Sarah Palin of this newsgroup,
Peter. Just as she failed to get an education and used the politics of
personal destruction in Wasilla to get ahead, you failed to take a
single computer science class and yet pose as an authority, with the
result that you've ruined Herb Schildt's reputation over a trivial
issue. You think the world owes you a living because you're
occasionally successful in actually programming, usually at the shell
procedure level, but you give no evidence whatsoever that you can
scale up. When people like Navia do scale up, you find fault with them
out of envy. When I claimed to scale up, and I claimed to have
published a "compiler", you led the charge to relabel it an
"interpreter".

When Herb scaled up, and mastered several programming languages, and
published a range of large books which the market judged to be worth
several editions (something that almost never happens to us Apress
hacks), you were beside yourself with rage, even as white, lower
middle class Americans with children who FAIL to succeed as Obama
succeeded are beside themselves with rage.

I was, in 2004, rather proud to have published with Apress, and I sent
free copies hither and yon...to my kids, to my math prof, and to my
Dad. But then Peter Neumann (the moderator of comp.risks) pointed out
to me that the index was poorly done. And, Dan Appleman, who
represented the Microsoft and Visual Basic interests at Apress, seems
to have disassociated himself with the firm.

And then you came along with your book. I don't know if your book is
any good, but your personal character makes me slightly ashamed to be
associated as an author with Apress. You violated Rule One of the
business world: don't knock the competition, just do a better job.

You are a Tea Bagger, in the Marxist objective sense, and I don't see
you voting for Obama if Palin runs.

Cute, redirecting replies to alt.test.
 
S

spinoza1111

I said nothing of the sort.  Not following this further in a C newsgroup,
though.

-s

It IS a C newsgroup issue, because YOU posted that "it's hard to
accept a black guy as President" because for the same reason you won't
interact with me properly, calling me a moron to third parties, you
can't stand it that a man who majored in the field he professes became
President.

Just as you turned around my emailed offer to discuss our issues, and
spare this ng months of flaming, you're not comfy around black people
or Microsoft programmers.

You work from home...a white privilege if there ever was one. And
queue.c's Coding Horrors (unstructured switch(), out of order
parameters after two months work) show that you became a "senior
systems programmer" because you are white, whilst my students of color
at DeVry paid thousands of dollars for degrees only to wind up working
at McDonald's, not because DeVry did a bad job but because of their
RACE.
 
S

spinoza1111

spinoza1111 said:
No, you want them to go crawling to thugs in insurance companies! UP
YOURS.

it is possible american "insurance companies" make Hospitals cost more
than it is right
why not copy the system[healt-care] some other nation, where all goes well?
for sys i mean the laws too

Signore, the problem with the technical petty bourgeois in America is
that they are embedded within the very systems that screw them.

American health care delivers the best outcomes in the world to people
with money or "gold-plated" insurance plans from their union or at
companies like Microsoft. But if you're (say) a contract programmer
who can't afford thousands of dollars in insurance premiums, you may
very well die of a treatable disease in a motel room or on the street.

The problem is that the complex public/private system we have (both
before and after Obamacare, which rejected a "public option"), an
enormous amount of unnecessary red tape and paperwork is generated,
but strangely all this red tape (including vast amounts of software)
is not recognized as "bureaucracy" when some private firm run by some
capitalist swine living on his own island generates the paperwork.

The petty bourgeoisie hopes to find or retain jobs handling this
enormous amount of paperwork, for example by writing and maintaining C
programs.

When my father was in the hospital, I had to put the same information
on multiple forms: one for the hospital, one for the (privatized for-
profit) anesthesiologist's firm and one for the (privatized for-
profit) radiologist's firm, because it was literally more important
for some pig doctors (unlike my MD father) to make millions by setting
up their own firms. The "waste" is somehow unnoticed, but should be
government ask you to fill out a form, it's Tea Party time.

In Hong Kong, the physician who saw me when I had a persistent cough
and was ferried for free by the cops cross the harbor had his own
personal X ray machine and knew how to use it. No separate charge, and
he was able to reassure me that the cough was caused by our pollution,
not lung cancer.

It is true that a radiologist with special training might have seen
precancerous conditions which an ER physician might miss, but such
practitioners can also miss things. One, in the USA, mistook my
pneumothorax scar for a tumor with the result that I shat bricks for
two weeks until another physician listened to me.

The relevance to C: in these PRIVATE bureaucracies, programmers
selected not for education and intelligence but for authoritarian
personalities (willing to suck up to management and bully their mates)
generate extraordinary amounts of waste motion through sheer
incompetence: they use strchr when they should use strstr. They waste
time writing strlen wrong. They handle a simple OR with fallthrough
switch() out of vanity. They declare constants as preprocessor
variables and then forget to use the variable. They claim to use
switch() to avoid copying code, and then copy code in a switch anyway,
getting the parameters out of order in one of the copies.

They spend most of their workday sniggering at people and playing
computer games, and they owe their jobs to a white skin in corporate
welfare. Whether they know it or not, Palin is their gal.
 
C

Colonel Harlan Sanders

But there is reason for hope: the great Tea Party movement that seeks to
reclaim America from the liberal elite. I predict a landslide victory for
President Palin in 2012 and the resurgence of our great country on the
international stage.

I was chortling at this brilliant parody... but later responses seem
to indicate that either he's great at staying in character, or he
really is the nutcase he looks like.

Looks like Spinoza has a rival in the stakes of "poster who is so
insane he defies parody". But I'm sure the reigning champ has the
stamina to pull ahead, his recent posts, for instance, attacking
Seebach's mother, responding to porno spam, his use of Hebrew in a
response to a Muslim poster, all speak of his great talent and
creativity in finding new ways of inserting his own head up his ass.
 
S

Seebs

And, when you have vastly more experience of English than you currently
do, it will perhaps be time to look up "irony".

It is surprisingly difficult to avoid overestimating the reading
comprehension Nilges brings to the table.

-s
 
P

Phil Carmody

Shawn P. Smithson said:
and clear that America is still a great nation under God, a land of

How the **** didn't I plonk this idiot first time round? I must
be slipping!

Phil
 
K

Kenny McCormack

(Kiki)
(Spinny)
But you don't ignore us here, and you are constantly complaining about
us, just like Hitler complained about the Jews.

Yes, that's exactly the point. If Kiki were genuine (that is, really
just trying to "save this newsgroup" [however He defines that concept]),
he'd do his tirades against us "trolls" in private email (this, assuming
that Kiki knows how to work email on the Internets).

The fact that he always does it in public shows that His real intent is
to "slime the trolls".

....
One can only wonder what sort of nut politics Kiki espouses.

Now, *that* is a scary thought, mister!

--
No, I haven't, that's why I'm asking questions. If you won't help me,
why don't you just go find your lost manhood elsewhere.

CLC in a nutshell.
 
K

Keith Thompson

Seebs said:
I understand your feelings about not feeding trolls and generally I
sympathize. But
[political opinions snipped]

It may be important, but:

1. This isn't the right group.

Exactly!

[more political opinions snipped]

I said this to Shawn P. Smithson, so for the sake of consistency
I'll say it to you. Please don't bring irrelevant political
discussions here. There will always be *someone* who can't resist
the urge to respond to something he or she stringly disagrees with.
Please don't be that someone.

The point of <http://xkcd.com/386/> is that duty *doesn't* call, and
the stick figure at the computer really should get up and go to bed.
 
S

spinoza1111

[political opinions snipped]


It may be important, but:
1.  This isn't the right group.

Exactly!

[more political opinions snipped]

I said this to Shawn P. Smithson, so for the sake of consistency
I'll say it to you.  Please don't bring irrelevant political
discussions here.  There will always be *someone* who can't resist
the urge to respond to something he or she stringly disagrees with.
Please don't be that someone.

Nothing is irrelevant apriori. If you're writing an application
program, you need to know about the application.

Many programmers find "academic computer science theory" irrelevant to
their concerns. They don't have the intelligence, creativity or energy
to see, for example, that a program vainly attempting to reconstruct
complete calls, including conference calls and forwarding, can be
rewritten as a simulator of the telephone switch. They don't listen to
the professor about stacks and program a reinsurance application that
loops when an insurance policy directly or indirectly self-insures.

They zone out in data base theory and create non-normalized tables.
They don't learn about set theory and craft switch-case which use null
fallthrough to handle 'A'...at three different locations in the same
switch case such that only the first case is used.

In later life, their anti-intellectualism generalizes into a sour and
focused resentment of difference and the other. In Arizona, they cheer
when poor immigrants are harassed. Online, they are always telling the
most literate, intelligent and good-humored posters to "stop
trolling".

"No use goin' on; de dam willains will keep a scougin' and slappin'
each
oder, Massa Stubb; dey don't hear one word; no use a-preaching to
such dam g'uttons as you call 'em, till dare bellies is full, and dare
bellies is bottomless; and when dey do get 'em full, dey wont hear you
den; for den dey sink in the sea, go fast to sleep on de coral, and
can't hear noting at all, no more, for eber and eber." - Herman
Melville, Moby Dick

Here, we find Seebs so incompetent and offensively so that we need to
speculate about psychology and politics. If he posted competent code,
we would not.

In your case, you so seldom contribute "relevant" material, and so
constantly complain about off topic "trolling" (which is by your
lights irrelevant meta-discussion) that we must perforce speculate on
your politics.
 
S

spinoza1111

spinoza1111wrote:


Look up "because". It doesn't mean what you seem to think it means.

And, when you have vastly more experience of English than you currently
do, it will perhaps be time to look up "irony".

I don't know in what Borstal, prison school, or special school you
studied English, Heathfield, but shove it up your ass. How much is
SAMS paying you to disrupt this newsgroup?
 
T

Tim Rentsch

Keith Thompson said:
2> Here is another macro
#define getc(p) (--(p)->cnt>=0 ?(unsigned char)*(p)->ptr++ :_fillbuf(p))
Doesn't that _fillbuf(p) ought to be _fillbuf((p)), one bracket for the
function call and one bracket to stop expansion of sideeffects in p?

No, extra parentheses aren't needed. As long as the name of the macro
parameter is immediately surrounded by parentheses (or brackets),
there's no problem with operator precedence. [snip]

C trivia question: for what kinds of <X> will the macro call
getc(<X>) behave differently if the body of '#define getc(p) ...'
is

(--(p)->cnt>=0 ?(unsigned char)*(p)->ptr++ :_fillbuf((p)))

rather than

(--(p)->cnt>=0 ?(unsigned char)*(p)->ptr++ :_fillbuf(p))

?

Hint: there are cases where it makes a difference.
 
T

Tim Rentsch

Eric Sosman said:
sandeep said:
[...]
Also if sizeof(char) == sizeof(int) then the character (unsigned char)
UCHARMAX will clash with EOF == -1 when it gets promoted to int.

getc() returns a result of type int, not char. For example, if
UCHAR_MAX is 255, then getc() will return the value 255 if you read a
'\xff' character, and the value -1 (assuming EOF==-1) if you encounter
the end of the stream or an error. They clash only if you store the
result in something smaller than an int. So don't do that.

I think you've misunderstood the question. On a system
where UCHAR_MAX > INT_MAX, getc() et al. have a problem: It
is possible to read unsigned char values that won't fit in an
int and hence can't be returned properly. What happens later
is of little importance, since the damage has been done within
getc() itself.

On such a system, I think we can deduce (for hosted
implementations)

- Conversion of values in (INT_MAX, UCHAR_MAX] doesn't raise
a signal or do anything untoward, but instead yields some
implementation-defined value. (At least, it does so inside
getc() et al, which need not be written in C.)

Seems right.
- Each unsigned char value converts to a distinct int value;
even the out-of-range conversions preserve information.

Seems right, except please note "distinct int value".
- Since there must be as many values in [INT_MIN, -1] as in
the span of out-of-range values, INT_MIN + INT_MAX == -1.
That is, two's complement is mandatory.

Possibly not. It's possible to consider negative zero as a
distinct int value. Negative zero compares equal to normal zero,
but it can be distinguished in other ways, eg, using bitwise
operations. An implementation could define handling of a
negative zero value such that signed magnitude or ones'
complement could also work.

An argument might be made that conversion of negative zero to
(unsigned char) would have to yield the value zero. I'm not sure
if this conclusion is right or not. However, even it that were
true, an implemenation could have a trap representation for the
negative zero bit pattern, and define the behavior of the trap
representation to be identical to that of negative zero, except
that converting it to an (unsigned char) maps it to that bit
pattern, not to zero. The trap representation "value" is allowed
to map to (unsigned char) however the implementation wants (and
may easily be produced by converting an (unsigned char) to (int),
etc.)

So I think it's possible for sizeof (char) == sizeof (int)
even in implementations that use s/m or 1's complement.

 
T

Tim Rentsch

Phil Carmody said:
Keith Thompson said:
I see the smiley, but referring to those of us who prefer to
discuss ISO C as "taliban" is a bit insulting, don't you think?
(And yes, I know the word literally means "students", but I doubt
that that's what you meant.) ...

No, extra parentheses aren't needed. As long as the name of the macro
parameter is immediately surrounded by parentheses (or brackets),
there's no problem with operator precedence.

And it's not about "expansion of side effects", it's about operator
precedence, i.e., which operators are associated with which operands.
Any side effects will occur anyway.

That's not quite the whole story, as the comma operator would
break the attempted _fillbuf call, were it to be able to reach
it, as it would not be interpreted as a comma operator. However,
that's not important because the processing of the macro can
never reach that stage, as it would require something that looks
like an invocation of the getc with 2 parameters, which wouldn't
be recognised as an instantiation of the above. [snip]

Not quite correct. It's possible for a valid call to the getc() macro
(as defined above) to have a call to _fillbuf() with more than one
argument (ie, with an unparenthesized comma in it) in the expansion.
 
S

Seebs

C trivia question: for what kinds of <X> will the macro call
getc(<X>) behave differently if the body of '#define getc(p) ...'
is

(--(p)->cnt>=0 ?(unsigned char)*(p)->ptr++ :_fillbuf((p)))

rather than

(--(p)->cnt>=0 ?(unsigned char)*(p)->ptr++ :_fillbuf(p))

?
Hint: there are cases where it makes a difference.

#define X a,b

-s
 
P

Phil Carmody

Tim Rentsch said:
Keith Thompson said:
2> Here is another macro
#define getc(p) (--(p)->cnt>=0 ?(unsigned char)*(p)->ptr++ :_fillbuf(p))
Doesn't that _fillbuf(p) ought to be _fillbuf((p)), one bracket for the
function call and one bracket to stop expansion of sideeffects in p?

No, extra parentheses aren't needed. As long as the name of the macro
parameter is immediately surrounded by parentheses (or brackets),
there's no problem with operator precedence. [snip]

C trivia question: for what kinds of <X> will the macro call
getc(<X>) behave differently if the body of '#define getc(p) ...'
is

(--(p)->cnt>=0 ?(unsigned char)*(p)->ptr++ :_fillbuf((p)))

rather than

(--(p)->cnt>=0 ?(unsigned char)*(p)->ptr++ :_fillbuf(p))

?

Hint: there are cases where it makes a difference.


-- 8< crap.c -----
#include <stdio.h>

typedef struct
{
int cnt;
char* ptr;
} THING;

#define GETC(p) (--(p)->cnt>=0 ?(unsigned char)*(p)->ptr++ :_FILLBUF(p))

#if FB==1
extern int _FILLBUF(THING* p) { p->cnt=9; return p->ptr[0]; }
#elif FB==2
extern int _FILLBUF(THING* p, THING* q) { p->cnt=9; return q->ptr[0]; }
#else
#error FB is 1 or 2
#endif

int main(void)
{
char buf[9];
THING x= { 0, buf };
THING*p=&x;
#define AB p,p
#define X AB
return GETC(X);
}
-- 8< -------

"""
phil@bazspaz:tmp$ gcc -DFB=1 -Wall -Wextra -c crap.c
crap.c: In function 'main':
crap.c:26: warning: left-hand operand of comma expression has no effect
crap.c:26: warning: left-hand operand of comma expression has no effect
crap.c:26: error: too many arguments to function '_FILLBUF'

phil@bazspaz:tmp$ gcc -DFB=2 -Wall -Wextra -c crap.c
crap.c: In function 'main':
crap.c:26: warning: left-hand operand of comma expression has no effect
crap.c:26: warning: left-hand operand of comma expression has no effect
"""

I take my hat of to you Tim; good one.

So the brackets are necessary in the face of adverse preprocessor use.

Phil
 
T

Tim Rentsch

Phil Carmody said:
[when f(X) in a macro body behaves unexpectedly]

I take my hat of to you Tim; good one.

So the brackets are necessary in the face of adverse preprocessor use.

C has a fair number of odd corners. It can be remarkably difficult
to code defensively against different kinds of unusual (but still
allowed) situations. Every so often it worries me a little bit to
realize I know about so many of them.

Thank you for the hats off, I'm glad it was of interest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

p 145 K&R 14
K&R 1-24 15
How to build a char[][] in k&r dialect. 7
p124 K&R 10
page 120 K&R 46
K$R xrcise 1-13 (histogram) 4
P 155 k&r section 7.3 35
K&R Exercise 1-21: entab 10

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top