How many levels of pointers can you have?

J

James Dow Allen

I wonder if anybody ever made a non toy program
with 12 levels of pointers.

Here's a program that uses 11 levels of pointers.
(It would have 12 but avoided the last level with
a "micro-optimization.")

http://james.fabpedigree.com/wnim.htm

Since the program was written in response
to a "non-life threatening" query in rec.puzzles,
I suppose it could be considered a "toy",
but the webpage poses a challenge: If this is
not the best way to solve the stated problem,
what is?

jamesdowallen at gmail
 
R

Richard Bos

James Dow Allen said:
Here's a program that uses 11 levels of pointers.
(It would have 12 but avoided the last level with
a "micro-optimization.")

http://james.fabpedigree.com/wnim.htm

Since the program was written in response
to a "non-life threatening" query in rec.puzzles,
I suppose it could be considered a "toy",
but the webpage poses a challenge: If this is
not the best way to solve the stated problem,
what is?

I'd have devised a way to encode the board, perhaps in a string, perhaps
in an unsigned long long if possible, and then used a one-dimensional
table of those. That's easier to extend to larger boards, for one thing.

Richard
 
L

lawrence.jones

Kenneth Brody said:
Now _there's_ a question for the standards committee... Where did
they pick the number 12 from?

As I recall, that was the limit in Ritchie's original compiler and no
one ever complained that it was too small, so the committee went with
it.

-Larry Jones

Even though we're both talking english, we're not speaking the same language.
-- Calvin
 
K

Keith Thompson

As I recall, that was the limit in Ritchie's original compiler and no
one ever complained that it was too small, so the committee went with
it.

-Larry Jones

Somebody here said that K&R (presumably the first edition) guarantees
6 levels. I don't have my copy handy to check this, but presumably
that would match what Ritchie's original compiler supported.
 
C

Charlton Wilbur

MML> However remember that the interviewer isn't really interested
MML> in technical ability - he knows that from your CV -

Er, you haven't seen some of the resumes I've seen, then, and
subsequently interviewed the candidates with the same name at the top
of the resume. The technical ability described on the resume may have
nothing at all to do with the technical ability possessed by the
candidate, and it is an irresponsible interviewer who does not
evaluate the candidate in front of him separately from what the resume
claims.

Charlton
 
E

Eric Sosman

Charlton said:
MML> However remember that the interviewer isn't really interested
MML> in technical ability - he knows that from your CV -

Er, you haven't seen some of the resumes I've seen, then, and
subsequently interviewed the candidates with the same name at the top
of the resume. The technical ability described on the resume may have
nothing at all to do with the technical ability possessed by the
candidate, and it is an irresponsible interviewer who does not
evaluate the candidate in front of him separately from what the resume
claims.

Seconded. I once found myself in a most embarrassing position
as an interviewee for a post I was not qualified for (nor interested
in). About five minutes into the interview, after I had answered
the Nth question in a row with "I dunno," the interviewer asked me
why in the world my resume claimed expertise in this area I was so
obviously unfamiliar with. I asked to see the resume, and to my
horror discovered that my headhunter had transformed my original
into a complete fabrication: He'd left my name intact, but just
invented most of the rest. I disavowed the fiction and promptly
on the next morning fired the headhunter -- but the damage was done;
even if the firm in question had a job for which I *was* suited, I
doubt they'd have hired me after that fiasco.

There are diligent and capable headhunters out there, but there
are also some utter sleazebags. "Trust, but verify."
 
R

Richard Heathfield

Eric Sosman said:

I once found myself in a most embarrassing position
as an interviewee for a post I was not qualified for (nor interested
in). About five minutes into the interview, after I had answered
the Nth question in a row with "I dunno," the interviewer asked me
why in the world my resume claimed expertise in this area I was so
obviously unfamiliar with. I asked to see the resume, and to my
horror discovered that my headhunter had transformed my original
into a complete fabrication: He'd left my name intact, but just
invented most of the rest. I disavowed the fiction and promptly
on the next morning fired the headhunter -- but the damage was done;
even if the firm in question had a job for which I *was* suited, I
doubt they'd have hired me after that fiasco.

One possible defence is to take your own copy of your CV to the
interview, so that you can show it to the interviewer during your
apology (which apology, by rights, the *headhunter* should be making).

I am, however, a little surprised that you got as far as the interview
stage without you yourself having found out about their requirements.
Two possibilities spring to mind - (a) a work-cultural difference
between your country and mine; (b) the headhunter was lying to *you*,
too. One cannot help but wonder what his motivation was, though. Trying
to bang Eric-shaped pegs into non-Eric-shaped holes must surely be a
losing proposition for all concerned.

For the record, if I'd been the interviewer I'd have said, "what, THE
Eric Sosman? Okay, never mind, we have THIS job for you instead..."
 
E

Eric Sosman

Richard said:
[...]
For the record, if I'd been the interviewer I'd have said, "what, THE
Eric Sosman? Okay, never mind, we have THIS job for you instead..."

A thousand thanks, but in that long-past time I was
not yet THE Eric Sosman; I was just Eric Sosman, young and
dumb. Nowadays I'm THE Eric Sosman, senile but cunning.
 
M

Malcolm McLean

Charlton Wilbur said:
MML> However remember that the interviewer isn't really interested
MML> in technical ability - he knows that from your CV -

Er, you haven't seen some of the resumes I've seen, then, and
subsequently interviewed the candidates with the same name at the top
of the resume. The technical ability described on the resume may have
nothing at all to do with the technical ability possessed by the
candidate, and it is an irresponsible interviewer who does not
evaluate the candidate in front of him separately from what the resume
claims.
Maybe that says more about the interview process than the candidate. That is
particularly true of computers. Put someone in front of an unfamiliar system
and he won't even know how to log on. That doesn't mean that within a few
days he won't be perfectly competent and productive.

Questions like "how many levels of indirection does C allow?" tell you a
little bit, but not much. Some programmers don't even use the term
"indirection", though they know what the concept means. An experienced
programmer might say "I don't know", because it is just a bit of trivia of
no real interest to anyone not actually implementing a compiler.

If people are coming to you claiming two years' experience as a C programmer
developing desktop apps with Blogg's corps, or possessing a degree in
computer studies, and seemingly now knowing basic things, then you really
need to look at what is going on. Whilst the candidate is trying to sell
himself and put a good gloss on his achievements, outright lying is
relatively rare, and in Britain at least is illegal. It could be that people
are elevating trivial exposure to something into wide experience, but then
you might be making the mistake of saying "we need someone who knows how to
log on to Unix".
 
J

James Dow Allen

I'd have devised a way to encode the board, perhaps in a string, perhaps
in an unsigned long long if possible, and then used a one-dimensional
table of those. That's easier to extend to larger boards, for one thing.

Yes, the one-dimensional table would be a hash table.
Readability is partly in beholder's eyes, but I'll
admit my choice gave high priority to whimsy, and
speed of *writing* (this was a program I never intended
to modify further, and "better" approaches would have
taken slightly longer to write, if less time to read).

Nevertheless, many-dimension sparse arrays would seem
an obvious case where "many levels of pointers"
could get used up quickly.

I'm sure there are many examples of
foo->bar->baz
in the Unix kernel.
Since an 'indent | grep' script would be easy to
write, it might be fun to look for any examples
of
foo->bar->baz->garf->grook
in real code.

James
 
J

Johan Bengtsson

James said:
Nevertheless, many-dimension sparse arrays would seem
an obvious case where "many levels of pointers"
could get used up quickly.

I'm sure there are many examples of
foo->bar->baz
in the Unix kernel.
Since an 'indent | grep' script would be easy to
write, it might be fun to look for any examples
of
foo->bar->baz->garf->grook
in real code.

James

Ooops, do you say that there might be a compiler dependent limits to the
number of a->b->c... levels i might use in a statement? I am probably
not using 12 or more, but probably not that far off at some places...
(I have a program where I have implemented object oriented programming
in C, (I didn't use C++ because it is also at the same time a plugin
structure using windows DLL:s, and those are a real pain i C++ BTDT)
using between two and four different structs for each hierarchy level,
and reaching a function pointer in the base "class" requires one -> for
each level plus two)
 
C

Chris Hills

Kira <[email protected]> said:
So yeah, 12 is safe everything above that is implementation defined.

Actually it is implementation defined anyway. Just because the standard
says 12 it does not mean there are 12. Some common architectures may not
support it.
I wonder if anybody ever made a non toy program with 12 levels of pointers.

There will always be at least one. The world is a nanny state in many
places and it has perverted the rule of Darwin. :)
 
F

Flash Gordon

Malcolm McLean wrote, On 09/06/07 08:49:
Maybe that says more about the interview process than the candidate.
That is particularly true of computers. Put someone in front of an
unfamiliar system and he won't even know how to log on. That doesn't
mean that within a few days he won't be perfectly competent and productive.

Questions like "how many levels of indirection does C allow?" tell you a
little bit, but not much. Some programmers don't even use the term
"indirection", though they know what the concept means. An experienced
programmer might say "I don't know", because it is just a bit of trivia
of no real interest to anyone not actually implementing a compiler.

It is not a question I would ask, but I would never just answer "I don't
know."
If people are coming to you claiming two years' experience as a C

Actually *having* X years experience does not mean that someone is any good.
programmer developing desktop apps with Blogg's corps, or possessing a
degree in computer studies, and seemingly now knowing basic things, then
you really need to look at what is going on.

Whatever the candidate you need to evaluate whether they have the
ability to do the job. This includes their problem solving abilities,
learning abilities, how much they already know about appropriate
subjects and whether they will fit in as a person.
> Whilst the candidate is
trying to sell himself and put a good gloss on his achievements,
outright lying is relatively rare, and in Britain at least is illegal.

It has cost the company I work for money. The company I used to work for
has also let someone go within a few months. In some other countries
(no, I won't say which) it seems to be far more common and/or more
extreme based on my real world experience.
It could be that people are elevating trivial exposure to something into
wide experience, but then you might be making the mistake of saying "we
need someone who knows how to log on to Unix".

My experience is that most companies are not making that mistake. I once
failed to get a job because I was "too good" despite 90% of my answers
being of the form, "well, I've not done that sort of thing before but I
would check in this sort of book and approach the problem like this",
and other interviews where the company has had my *real* CV and I've
come close to getting the job despite obviously not having some of what
they wanted.

I am in Britain.
 
J

Joachim Schmitz

Chris Hills said:
Actually it is implementation defined anyway. Just because the standard
says 12 it does not mean there are 12. Some common architectures may not
support it.
Less then 12? But that wouldn't be a conforming implementation then, would
it?

Bye, Jojo
 
C

Chris Hills

Joachim Schmitz said:
Less then 12? But that wouldn't be a conforming implementation then, would
it?
Bye, Jojo

That is what I said.
95% of the C compilers aren't fully C99 conforming anyway.

AFAIK there are only about 6 compilers in the world that are fully C99
conforming. The other 100 odd are not to a greater or lesser extent.

The practical and realistic answer is to the question it that it is
implementation dependant but that the standard says 12.

Unless and until there is a legal requirement to use a fully conforming
C compiler (to the latest ISO C standard) you with find that the ISO C
standard is a theoretical standard for compilers to aspire to but that
few actually conform to.

So you can give a theoretically accurate answer that is practically
speaking pointless.

I have never seen any "C" compiler advertised as "C-Like" or "nearly
conforming" They are just C-compilers. You have to read the docs to
check the actual spec.
 
C

Chris Dollin

Chris said:
Actually it is implementation defined anyway. Just because the standard
says 12 it does not mean there are 12.

If there are not, the implementation isn't conformant. Nothing stops
you from using a non-conforming system, just as nothing stops you
from using Fortran or Spitbol; it's just not a conforming C
implementation. That's OK as long as its not advertised as
conforming and as long as you don't expect to port conforming
code to it.
Some common architectures may not support it.

I'm not sure what this "it" is. What do you mean here by "architecture"?
The compiler design? Sure, I can imagine writing a compiler that
wilfully limited how many levels of pointer I could have in a
declaration; but I can also imagine eating wallpaper or swimming
in vinegar.
 
J

Joachim Schmitz

Chris Hills said:
That is what I said.
95% of the C compilers aren't fully C99 conforming anyway.
So what does C89 require as the minmum?

Bye, Jojo
 
R

Richard Tobin

Johan Bengtsson said:
Ooops, do you say that there might be a compiler dependent limits to the
number of a->b->c... levels i might use in a statement? I am probably
not using 12 or more, but probably not that far off at some places...

The "12" came from the minimum limit on * in a declaration such as

int ***a;

The case of a->b->c->... is a separate question of expression complexity.

Incidentally, if we have

int ************a; /* 12 stars */

then &a has a type with 13 levels of indirection, so an implementation
has to be able to support the type of

int *************a; /* 13 stars */

-- Richard
 
J

Johan Bengtsson

Richard said:
The "12" came from the minimum limit on * in a declaration such as

int ***a;

The case of a->b->c->... is a separate question of expression complexity.
Ahh, thought so, thanks
 
C

Chris Hills

Chris said:
If there are not, the implementation isn't conformant. Nothing stops
you from using a non-conforming system,

That's good as none of them (bar a few) are fully conforming. In most
fields of C programming there are no C compilers.
just as nothing stops you
from using Fortran or Spitbol; it's just not a conforming C
implementation. That's OK as long as its not advertised as
conforming and as long as you don't expect to port conforming
code to it.

They are just advertised as "C compilers" not ISO 989:1999 conforming C
compilers.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top