Merrill & Michele
Guest
Posts: n/a

 10-10-2004
A recent thread discussed turning 4 given bytes in a particular order to a
long. While studying this, I encountered K&R §2.9, where the following
expression is said to mask off all but the first seven bits:

n=n & 0177;

This would have seemed right to me if 1+2+4+...+64 (seven terms) equaled
something other than 127. Ideas? MPJ

Artie Gold
Guest
Posts: n/a

 10-10-2004
Merrill & Michele wrote:
> A recent thread discussed turning 4 given bytes in a particular order to a
> long. While studying this, I encountered K&R §2.9, where the following
> expression is said to mask off all but the first seven bits:
>
> n=n & 0177;
>
> This would have seemed right to me if 1+2+4+...+64 (seven terms) equaled
> something other than 127. Ideas? MPJ
>
>

0177 == 127
026 == 22
011 == 9

and so on.

HTH,
--ag

--
Artie Gold -- Austin, Texas

"If you don't think it matters, you're not paying attention."

Mike Wahler
Guest
Posts: n/a

 10-10-2004

"Merrill & Michele" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> A recent thread discussed turning 4 given bytes in a particular order to a
> long. While studying this, I encountered K&R §2.9, where the following
> expression is said to mask off all but the first seven bits:
>
> n=n & 0177;
>
> This would have seemed right to me if 1+2+4+...+64 (seven terms) equaled
> something other than 127. Ideas? MPJ

0177 (and any integer literal beginning with digit '0')
is in base 8. Personally, I prefer to use hex constants
("0x" prefix) for expressing bit patterns (I can more readily
mentally convert them to/from binary).

-Mike

Peter Nilsson
Guest
Posts: n/a

 10-11-2004
"Mike Wahler" <(E-Mail Removed)> wrote in message news:<dT4ad.955\$(E-Mail Removed) nk.net>...
>
> 0177 (and any integer literal beginning with digit '0')
> is in base 8.

Note though that pp-number tokens do not have a base. A token like
0188 is perfectly valid and could be used with macro operators.

--
Peter

Dan Pop
Guest
Posts: n/a

 10-11-2004
In <(E-Mail Removed) > http://www.velocityreviews.com/forums/(E-Mail Removed) (Peter Nilsson) writes:

>"Mike Wahler" <(E-Mail Removed)> wrote in message news:<dT4ad.955\$(E-Mail Removed) nk.net>...
>>
>> 0177 (and any integer literal beginning with digit '0')
>> is in base 8.

>
>Note though that pp-number tokens do not have a base. A token like
>0188 is perfectly valid and could be used with macro operators.

pp-numbers that aren't evaluated by the preprocessor as integers and
don't survive translation phase 4 as single tokens are not particularly
relevant to *any* discussion about integer literals.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
Currently looking for a job in the European Union

Dan Pop
Guest
Posts: n/a

 10-11-2004
In <(E-Mail Removed)> "Merrill & Michele" <(E-Mail Removed)> writes:

>A recent thread discussed turning 4 given bytes in a particular order to a
>long. While studying this, I encountered K&R §2.9, where the following
>expression is said to mask off all but the first seven bits:
>
>n=n & 0177;
>
>This would have seemed right to me if 1+2+4+...+64 (seven terms) equaled
>something other than 127. Ideas? MPJ

Before using K&R2 as a reference text, you MUST use it as a tutorial, i.e.
read *all* of it (at least until chapter in strict sequence.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
Currently looking for a job in the European Union

Merrill & Michele
Guest
Posts: n/a

 10-11-2004

> > MPJ wrote:
> >A recent thread discussed turning 4 given bytes in a particular order to

a
> >long. While studying this, I encountered K&R §2.9, where the following
> >expression is said to mask off all but the first seven bits:
> >
> >n=n & 0177;
> >
> >This would have seemed right to me if 1+2+4+...+64 (seven terms) equaled
> >something other than 127. Ideas? MPJ

> Dan Pop wrote:
> Before using K&R2 as a reference text, you MUST use it as a tutorial, i.e.
> read *all* of it (at least until chapter in strict sequence.
>

Such was my resolve when I bought it sight unseen. I wanted my C
development to be ANSI compliant. Imagine my surprise when the first prog
had a non-conforming main() call followed by his laying of the

Richard Bos
Guest
Posts: n/a

 10-12-2004
"Merrill & Michele" <(E-Mail Removed)> wrote:

> > Before using K&R2 as a reference text, you MUST use it as a tutorial, i.e.
> > read *all* of it (at least until chapter in strict sequence.

>
> Such was my resolve when I bought it sight unseen. I wanted my C
> development to be ANSI compliant. Imagine my surprise when the first prog
> had a non-conforming main() call followed by his laying of the
> implementation egg.

Care to explain?
Imprimis, AFAIR, the first program from K&R 2 is quite conforming to the
Standard it uses. Remember that K&R was written before 1999, so it
necessarily uses C89, under which implicit int is legal.
Secundis, whatever do you mean by "his laying of the implementation
egg"? That phrase doesn't make sense to me.

Richard

Mabden
Guest
Posts: n/a

 10-12-2004
"Richard Bos" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Merrill & Michele" <(E-Mail Removed)> wrote:
>
> > > Before using K&R2 as a reference text, you MUST use it as a

tutorial, i.e.
> > > read *all* of it (at least until chapter in strict sequence.

> >
> > Such was my resolve when I bought it sight unseen. I wanted my C
> > development to be ANSI compliant. Imagine my surprise when the

first prog
> > had a non-conforming main() call followed by his laying of the
> > implementation egg.

>
> Care to explain?
> Imprimis, AFAIR, the first program from K&R 2 is quite conforming to

the
> Standard it uses. Remember that K&R was written before 1999, so it
> necessarily uses C89, under which implicit int is legal.
> Secundis, whatever do you mean by "his laying of the implementation
> egg"? That phrase doesn't make sense to me.

Obviously, he refers to the phrase, "hello, world".
What happens when one tries to learn C in space???

--
Mabden

Merrill & Michele
Guest
Posts: n/a

 10-12-2004

> > > > Dan wrote:
> > > > Before using K&R2 as a reference text, you MUST use it as a
> > > > tutorial, i.e.
> > > > read *all* of it (at least until chapter in strict sequence.

> > > MPJ wrote:
> > > Such was my resolve when I bought it sight unseen. I wanted my C
> > > development to be ANSI compliant. Imagine my surprise when the
> > > first prog
> > > had a non-conforming main() call followed by his laying of the
> > > implementation egg.

> > Richard wrote:
> > Care to explain?
> > Imprimis, AFAIR, the first program from K&R 2 is quite conforming to
> > the
> > Standard it uses. Remember that K&R was written before 1999, so it
> > necessarily uses C89, under which implicit int is legal.

Is the following program ANSI C when I shelled out \$40 for K&R2 in 2004:

#include <stdio.h>

main()
{
printf("hello, world\n");
}

Never mind style. Is it conforming?

> > Secundis, whatever do you mean by "his laying of the implementation
> > egg"? That phrase doesn't make sense to me.

We'll revisit that one.

> Mabden wrote:
> Obviously, he refers to the phrase, "hello, world".
> What happens when one tries to learn C in space???

Sarcasm. MPJ