Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C Programming Language

How many levels of pointers can you have?


This question is occur in interview. Please help me.
"madhawi" <madhaw@gmail.com> schrieb im Newsbeitrag
news:1181148059.510383.20700@z28g2000prd.googlegroups.com...
> This question is occur in interview. Please help me.

What question?

Ahh, in the Subject... don't hide it there.

>How many levels of pointers can you have?

no chapter and verse, but I believe that is implementatiion defined.

madhawi <madhaw@gmail.com> writes:
> Subject: How many levels of pointers can you have?

> This question is occur in interview. Please help me.

Twelve:

     5.2.4.1 Translation limits
1    The implementation shall be able to translate and execute at
     least one program that contains at least one instance of
     every one of the following limits:13)
[...]
     - 12 pointer, array, and function declarators (in any
       combinations) modifying an arithmetic, structure, union,
       or incomplete type in a declaration

--
Comp-sci PhD expected before end of 2007
Seeking industrial or academic position *outside California* in 2008

In article <1181148059.510383.20@z28g2000prd.googlegroups.com>,

madhawi  <madhaw@gmail.com> wrote:
>This question is occur in interview. Please help me.

At least 12.  (See the section "Declarators" in the standard.)

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.

On Jun 6, 9:40 pm, madhawi <madhaw@gmail.com> wrote:

> This question is occur in interview. Please help me.

answer of course is implementation specific. if my memory is correct i
think it is 71 levels of indirection in borland turbo c++ version 3.0
compiler.

Ben Pfaff wrote:

> madhawi <madhaw@gmail.com> writes:

> > Subject: How many levels of pointers can you have?

> > This question is occur in interview. Please help me.

> Twelve:

"At least 12."

>      5.2.4.1 Translation limits
> 1    The implementation shall be able to translate and execute at
>      least one program that contains at least one instance of
>      every one of the following limits:13)
> [...]
>      - 12 pointer, array, and function declarators (in any
>        combinations) modifying an arithmetic, structure, union,
>        or incomplete type in a declaration

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

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody        | www.hvcomputer.com | #include              |
| kenbrody/at\spamcop.net | www.fptech.com     |    <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamT@gmail.com>

Kenneth Brody <kenbr@spamcop.net> writes:
> Now _there's_ a question for the standards committee...  Where did
> they pick the number 12 from?

One member wanted 8, another wanted 16, they compromised on 12?
--
Ben Pfaff
http://benpfaff.org
Ben Pfaff said:

> Kenneth Brody <kenbr@spamcop.net> writes:

>> Now _there's_ a question for the standards committee...  Where did
>> they pick the number 12 from?

> One member wanted 8, another wanted 16, they compromised on 12?

No no no. It's a committee! One member wanted 16, another wanted 16,
another wanted 16, and quite a few more wanted 16, and everybody else
also wanted 16, so they compromised on 12.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.

"Kenneth Brody" <kenbr@spamcop.net> wrote in message

news:4667123D.ECF7A259@spamcop.net...

> Ben Pfaff wrote:

>> madhawi <madhaw@gmail.com> writes:

>> > Subject: How many levels of pointers can you have?

>> > This question is occur in interview. Please help me.

>> Twelve:

> "At least 12."

So yeah, 12 is safe everything above that is implementation defined.
I wonder if anybody ever made a non toy program with 12 levels of pointers.

madhawi wrote:
> This question is occur in interview. Please help me.

     One: a pointer points to its target, and that's that.

--
Eric Sosman
esos@acm-dot-org.invalid

Maybe all the compilers allowed "as many as you like (until we
run out of store)", except one that had a 4-bit field for
"number of indirections" in a type with the top three values
reserved for "struct", "union", or "function pointer".

--
Speculative Faction Hedgehog
Otherface: Jena RDF/Owl toolkit http://jena.sourceforge.net/

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

from C89

--
Tor <torust [at] online [dot] no>

Ben Pfaff wrote:

> madhawi <madhaw@gmail.com> writes:

> > Subject: How many levels of pointers can you have?

> > This question is occur in interview. Please help me.

> Twelve:

/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
    (************puts)("Cool!!!");
    return 0;

}

/* END new.c */

--
pete

In article <4cF9i.13712$hj5.10@fe2.news.blueyonder.co.uk>,
Chris Dollin  <e@electrichedgehog.net> wrote:

I have a vague memory from many years back about what I believe was a
Honeywell mainframe (36 bit words, 18 bit addressing). One of the features
of this beast was indirect addressing where if a bit was set in a word
when it was accessed, it indicated that the word should be used as an
address pointing to where the actual parameter was. And if *that* had that
magic bit set, then it was also an address pointing to where the actual
parameter was. This indirection could in theory go quite a distance. However
the computer would throw an exception if too many levels of indirection
were being used. I don't remember how many levels this was.

But given that the above feature could be used to implement pointer to pointer
to ..... in a fairly efficient C implementation. I can see a "must be able
to do at least X levels of indirection" requirement based upon the limits
of the computers with this capability.

Now this is pure speculation, but I wouldn't be surprised if there exists
a modern computer that has this indirect capability and has a limit on
how many levels of indirection it's willing to perform without causing
an exception.

In article <f478gr$2n9@smof.fiawol.org>,

John Cochran <j@smof.fiawol.org> wrote:
>I have a vague memory from many years back about what I believe was a
>Honeywell mainframe (36 bit words, 18 bit addressing). One of the features
>of this beast was indirect addressing where if a bit was set in a word
>when it was accessed, it indicated that the word should be used as an
>address pointing to where the actual parameter was. And if *that* had that
>magic bit set, then it was also an address pointing to where the actual
>parameter was. This indirection could in theory go quite a distance. However
>the computer would throw an exception if too many levels of indirection
>were being used. I don't remember how many levels this was.

>But given that the above feature could be used to implement pointer to pointer
>to ..... in a fairly efficient C implementation. I can see a "must be able
>to do at least X levels of indirection" requirement based upon the limits
>of the computers with this capability.

I doubt C has ever been implemented on that architecture by setting
the relevant bit in pointers.  If we have char *****p, then both **p
and ****p are legal expressions: the number of dereferences is
controlled by the program, not the data.  C doesn't have a
"dereference as much as you can" operator.

>Now this is pure speculation, but I wouldn't be surprised if there exists
>a modern computer that has this indirect capability and has a limit on
>how many levels of indirection it's willing to perform without causing
>an exception.

I *would* be surprised if there was such a modern computer.

In any case, the limit in C89 - which is a limit on types, not
dereferencing of objects - most likely just reflects how some common
existing implementation handled declarations.

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.

Yes, but like all the limits in 5.2.4.1, it doesn't necessarily mean
very much.  A conforming implementation is merely required to
translate and execute *one* program that hits all the listed limits.
Another program with 12 levels of pointers might fail to compile.

The point of the requirement, I think, is that the easiest way to
satisify it is not to have any fixed limits at all, by making the
relevant data structures within the compiler dynamic.  A typical
compiler most likely won't complain about 13, or 20, or 99 levels of
pointers (unless it issues a warning).

--
Keith Thompson (The_Other_Keith) k@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

On Jun 7, 8:49 am, "Kira" <a@n.tk> wrote:

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

Does this count? :)
http://groups.google.co.nz/group/alt.comp.lang.learn.c-c++/msg/6a167c...
Old Wolf said:

> On Jun 7, 8:49 am, "Kira" <a@n.tk> wrote:
>> I wonder if anybody ever made a non toy program with 12 levels of
>> pointers.

> Does this count? :)

http://groups.google.co.nz/group/alt.comp.lang.learn.c-c++/msg/6a167c...

That was a pretty fun thread from top to bottom.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.

I suspect a vote, about 20 years ago, long forgotten.

--
 <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
 <http://www.securityfocus.com/columnists/423>
 <http://www.aaxnet.com/editor/edit043.html>
 <http://kadaitcha.cx/vista/dogsbreakfast/index.html>
                        cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

On Wed, 06 Jun 2007 15:59:57 -0400, Kenneth Brody

<kenbr@spamcop.net> wrote:
>Now _there's_ a question for the standards committee...  Where did
>they pick the number 12 from?

I think they just doubled the 6 guaranteed by K&R.  Studies showed
that some complicated code used 6 or more indirections but that
virtually no code used more than 10.

George
--
for email reply remove "/" from address

"madhawi" <madhaw@gmail.com> wrote in message

news:1181148059.510383.20700@z28g2000prd.googlegroups.com...
> This question is occur in interview. Please help me.

You might know you might not.
The point is that the standard imposes some limit which is way above the
number of dereferences any paractical programmer would ever need. All
computers will eventually run out of memory if you try to impose a stupidly
large number, even if it is 4 billion.

As it stands it is rather a bad question. It tells you who knows every
irrelevant detail of the stnadard, but that only has a slight correlation to
broader abilities. However remember that the interviewer isn't really
interested in technical ability - he knows that from your CV - he wants to
find out what sort of person you are. So given that you don't know, how do
you handle that? If you can do it in a graceful and relaxed manner, but not
too arrogant - they are looking for teamworking skills, aka obedience, after
all - then you should do well.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

On Jun 7, 3:49 am, "Kira" <a@n.tk> wrote:

> 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

James Dow Allen <jdallen2@yahoo.com> wrote:

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

Malcolm McLean wrote:
> "madhawi" <madhaw@gmail.com> wrote in message

>> This question is occur in interview. Please help me.

> You might know you might not.  The point is that the standard
> imposes some limit which is way above the number of dereferences
> any paractical programmer would ever need. All computers will
> eventually run out of memory if you try to impose a stupidly
> large number, even if it is 4 billion.

Why?  All the dereference requires is to replace the pointer with
what it points to.  Repeat as each '*' appears in the input.  At
most this requires games with the input stream, such as counting
'*'s while advancing to the base pointer.

--
 <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
 <http://www.securityfocus.com/columnists/423>
 <http://www.aaxnet.com/editor/edit043.html>
 <http://kadaitcha.cx/vista/dogsbreakfast/index.html>
                        cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Kenneth Brody <kenbr@spamcop.net> wrote:

> 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

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc