For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > December 2004 > File * to fd









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author File * to fd
Kamal R. Prasad

2004-12-24, 4:16 am

From: Jens.Toerring@physik.fu-berlin.de
(Jens.Toerring@physik.fu-berlin.de)
Subject: Re: File * to fd

View this article only
Newsgroups: comp.unix.programmer
Date: 2004-12-23 11:04:14 PST

Kamal R. Pra <kamalp@acm.org> wrote:
> From: termbios (meson@techemail.com)
into[color=darkred]
> a file descriptor. Is there a function call for it? Like fdopen create
> a FILE* out of a file descriptor.
> FILE (struct __sFILE) has a member
> short _file; /* fileno, if Unix descriptor, else -1 */
> so, you just need to access (assuming your FILE* is fp) fp->_file to
> access the related file descriptor. Im not aware if the member varies
> across implementations -but if it doesn't, you save yourself a
> function call by accessing the member directly.


"There's no guarantee anywhere that the FILE structure must have a
member called '_file' and that this is the file descriptor asso-
ciated with the file - while fileno() is a well-defined function
required by POSIX. So using '_file' is a horribly stupid idea. All
you get that way is a program that you never know if it's going to
work correctly on the next platform for the dubious benefit of saving
a few nanoseconds at best from time to time. Giving such advice is
like telling a little child to cross a busy street where it is - "That
big lorry is going to stop for you, don't you worry" - instead of
going
to the traffic light 5 meters away in order to save a few steps.

Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de

"
Fine. I usually write code that is closely tied to the OS and
underlying hw -and so I gave that suggestion. It is probably a stupid
idea to do so, if fileno() is a macro. One of the problems with POSIX
is that it doesn't state what the overhead to a circutious route might
be. Maybe its upto the implementation -but they just don't bother
about stating the overhead.

regards
-kamal
Casper H.S. Dik

2004-12-24, 3:57 pm

kamalp@acm.org (Kamal R. Pra) writes:

>Fine. I usually write code that is closely tied to the OS and
>underlying hw -and so I gave that suggestion. It is probably a stupid
>idea to do so, if fileno() is a macro. One of the problems with POSIX
>is that it doesn't state what the overhead to a circutious route might
>be. Maybe its upto the implementation -but they just don't bother
>about stating the overhead.


Surely there must be some programmer's proverb like "penny wise,
pound foolish" (cycle savvy, maintenance hazard?)

You should *never* circumvent a standard interface because you
think it's faster; apart from the fact that performance and intuition
don't go well together and that people generally optimize the bits
which are not performance critical, you also increase you maintenance
and portability issues.

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Kenny McCormack

2004-12-24, 3:57 pm

In article <41cc401d$0$6214$e4fe514c@news.xs4all.nl>,
Casper H.S. Dik <Casper.Dik@Sun.COM> wrote:
>kamalp@acm.org (Kamal R. Pra) writes:
>
>
>Surely there must be some programmer's proverb like "penny wise,
>pound foolish" (cycle savvy, maintenance hazard?)
>
>You should *never* circumvent a standard interface because you
>think it's faster; apart from the fact that performance and intuition
>don't go well together and that people generally optimize the bits
>which are not performance critical, you also increase you maintenance
>and portability issues.


That is usually the goal.

Don't want to be out-sourced, do ya?

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com