How many levels of pointers can you have?

Discussion in 'C Programming' started by madhawi, Jun 6, 2007.

  1. madhawi

    madhawi Guest

    This question is occur in interview. Please help me.
     
    madhawi, Jun 6, 2007
    #1
    1. Advertising

  2. "madhawi" <> schrieb im Newsbeitrag
    news:...
    > 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.
     
    Joachim Schmitz, Jun 6, 2007
    #2
    1. Advertising

  3. madhawi

    Ben Pfaff Guest

    madhawi <> 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
     
    Ben Pfaff, Jun 6, 2007
    #3
  4. In article <>,
    madhawi <> 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.
     
    Richard Tobin, Jun 6, 2007
    #4
  5. madhawi

    siju Guest

    On Jun 6, 9:40 pm, madhawi <> 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.
     
    siju, Jun 6, 2007
    #5
  6. Ben Pfaff wrote:
    >
    > madhawi <> 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:>
     
    Kenneth Brody, Jun 6, 2007
    #6
  7. madhawi

    Ben Pfaff Guest

    Kenneth Brody <> 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, Jun 6, 2007
    #7
  8. Ben Pfaff said:

    > Kenneth Brody <> 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.
     
    Richard Heathfield, Jun 6, 2007
    #8
  9. madhawi

    Kira Guest

    "Kenneth Brody" <> wrote in message
    news:...
    > Ben Pfaff wrote:
    >>
    >> madhawi <> 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.
     
    Kira, Jun 6, 2007
    #9
  10. madhawi

    Eric Sosman Guest

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


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

    --
    Eric Sosman
    lid
     
    Eric Sosman, Jun 6, 2007
    #10
  11. madhawi

    Chris Dollin Guest

    Kenneth Brody wrote:

    > Ben Pfaff wrote:
    >>
    >> madhawi <> 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?


    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/
     
    Chris Dollin, Jun 6, 2007
    #11
  12. madhawi

    Tor Rustad Guest

    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>
     
    Tor Rustad, Jun 6, 2007
    #12
  13. madhawi

    pete Guest

    Ben Pfaff wrote:
    >
    > madhawi <> 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
     
    pete, Jun 6, 2007
    #13
  14. madhawi

    John Cochran Guest

    In article <4cF9i.13712$>,
    Chris Dollin <> wrote:
    >Kenneth Brody wrote:
    >
    >> Ben Pfaff wrote:
    >>>
    >>> madhawi <> 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?

    >
    >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".


    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.
     
    John Cochran, Jun 6, 2007
    #14
  15. In article <f478gr$2n99$>,
    John Cochran <> 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.
     
    Richard Tobin, Jun 6, 2007
    #15
  16. Ben Pfaff <> writes:
    > madhawi <> 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


    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) <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"
     
    Keith Thompson, Jun 6, 2007
    #16
  17. madhawi

    Old Wolf Guest

    Old Wolf, Jun 7, 2007
    #17
  18. Richard Heathfield, Jun 7, 2007
    #18
  19. On Wed, 06 Jun 2007 15:59:57 -0400, Kenneth Brody
    <> 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
     
    George Neuner, Jun 7, 2007
    #19
  20. "madhawi" <> wrote in message
    news:...
    > 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
     
    Malcolm McLean, Jun 7, 2007
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,365
  2. =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?=

    Running totals in gridview (when you have many totals required)

    =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?=, Feb 15, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    891
    Alexey Smirnov
    Feb 16, 2007
  3. shoplifes
    Replies:
    0
    Views:
    323
    shoplifes
    Nov 25, 2007
  4. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    729
  5. damezumari
    Replies:
    18
    Views:
    569
    Richard Cornford
    Dec 20, 2006
Loading...

Share This Page