Re: An interview question

Discussion in 'C Programming' started by Ian Collins, Mar 5, 2010.

  1. Ian Collins

    Ian Collins Guest

    Debanjan wrote:
    > Does there exist any other alternative data structure instead of
    > struct tm (having same memory allocated as this structure) ? So that I
    > could use strftime without declaring <time.h>
    >
    > I am aware of the fact that relying on implicit declaration is not
    > good,but I faced this question in an interview.
    >
    > To be precise I was asked to print the month for a corresponding
    > integer using standard library function,but not allowed to include any
    > header file.


    That's about as bad as being asked to complete a driving test without
    using a car.

    You can't safely use any standard library functions without including
    the headers that declare them and their data structures.

    --
    Ian Collins
     
    Ian Collins, Mar 5, 2010
    #1
    1. Advertising

  2. Ian Collins

    Ben Pfaff Guest

    Ian Collins <> writes:

    > You can't safely use any standard library functions without including
    > the headers that declare them and their data structures.


    I don't recommend doing it, but some standard library functions
    may legitimately be used without including the appropriate
    standard header:

    7.1.4 Use of library functions
    ....
    2 Provided that a library function can be declared without
    reference to any type defined in a header, it is also
    permissible to declare the function and use it without
    including its associated header.
    --
    "...what folly I commit, I dedicate to you."
    --William Shakespeare, _Troilus and Cressida_
     
    Ben Pfaff, Mar 5, 2010
    #2
    1. Advertising

  3. Ian Collins

    Ian Collins Guest

    Ben Pfaff wrote:
    > Ian Collins <> writes:
    >
    >> You can't safely use any standard library functions without including
    >> the headers that declare them and their data structures.

    >
    > I don't recommend doing it, but some standard library functions
    > may legitimately be used without including the appropriate
    > standard header:
    >
    > 7.1.4 Use of library functions
    > ....
    > 2 Provided that a library function can be declared without
    > reference to any type defined in a header, it is also
    > permissible to declare the function and use it without
    > including its associated header.


    That's why I added "and their data structures"!

    In the OP's context, struct tm is a classic case of a structure defined
    (by the standard) to include minimum set of members. An implementation
    is free to add some of its own.

    --
    Ian Collins
     
    Ian Collins, Mar 5, 2010
    #3
  4. Ian Collins

    Ben Pfaff Guest

    Ian Collins <> writes:

    > Ben Pfaff wrote:
    >> Ian Collins <> writes:
    >>
    >>> You can't safely use any standard library functions without including
    >>> the headers that declare them and their data structures.

    >>
    >> I don't recommend doing it, but some standard library functions
    >> may legitimately be used without including the appropriate
    >> standard header:
    >>
    >> 7.1.4 Use of library functions
    >> ....
    >> 2 Provided that a library function can be declared without
    >> reference to any type defined in a header, it is also
    >> permissible to declare the function and use it without
    >> including its associated header.

    >
    > That's why I added "and their data structures"!


    I can use exit() by declaring it myself, without including
    <stdlib.h>, but your statement (quoted above) says that I can't.
    So your statement is wrong.
    --
    "IMO, Perl is an excellent language to break your teeth on"
    --Micah Cowan
     
    Ben Pfaff, Mar 5, 2010
    #4
    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. Gopal Krish

    Interview question

    Gopal Krish, Oct 22, 2004, in forum: ASP .Net
    Replies:
    10
    Views:
    681
    John Timney \(Microsoft MVP\)
    Oct 23, 2004
  2. Digital Puer
    Replies:
    17
    Views:
    4,011
    Andrew Thompson
    Dec 27, 2003
  3. Jerry

    An interview question

    Jerry, May 27, 2005, in forum: Java
    Replies:
    22
    Views:
    938
    Brooks Hagenow
    Jun 12, 2005
  4. Replies:
    9
    Views:
    459
    Andrey Tarasevich
    Jan 22, 2005
  5. reema
    Replies:
    0
    Views:
    281
    reema
    Aug 26, 2008
Loading...

Share This Page