Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: An interview question

Reply
Thread Tools

Re: An interview question

 
 
Ian Collins
Guest
Posts: n/a
 
      03-05-2010
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
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      03-05-2010
Ian Collins <ian-> 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_
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      03-05-2010
Ben Pfaff wrote:
> Ian Collins <ian-> 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
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      03-05-2010
Ian Collins <ian-> writes:

> Ben Pfaff wrote:
>> Ian Collins <ian-> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP Interview Questions ASP Interview Questions reema ASP General 0 08-26-2008 11:57 AM
.NET Interview Question, C#, ASP.NET Interview Questions dotnetuncle Javascript 0 10-30-2007 03:08 PM
An interview question Jerry Java 22 06-12-2005 03:55 PM
Interview question Gopal Krish ASP .Net 10 10-23-2004 10:18 AM
interview question (toughest bug you've fixed)? Digital Puer Java 17 12-27-2003 09:35 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57