Use both C/C++ library?

Discussion in 'C++' started by Immortal Nephi, Apr 10, 2010.

  1. C Run-Time Library has most functions available to all platforms such
    as Windows, Mac OSX, and Linux. Some functions start one underscore
    before function name ( _funcname() ) are Microsoft Specification.
    Some functions are not the same as Mac OSX and Linux have.
    C++ iostream library uses some C Run-Time library functions such as
    file management. It only has open() and close(), but it does not have
    additional file functions such as rename, delete, display directory,
    change file size, etc.
    The file management in C++ iostream library has limited error
    reporting message. The error message tells that file can’t be opened,
    but it does not specify more details such as disk is full or file is
    corrupted or file does not exist.
    Do you suggest to use both C Run-Time library and C++ iostream
    library when you want to write your code to work all platforms? C Run-
    Time library should have full error reporting management from all
    operating systems.
     
    Immortal Nephi, Apr 10, 2010
    #1
    1. Advertising

  2. Immortal Nephi

    red floyd Guest

    On 4/10/2010 9:20 AM, Immortal Nephi wrote:
    > C Run-Time Library has most functions available to all platforms such
    > as Windows, Mac OSX, and Linux. Some functions start one underscore
    > before function name ( _funcname() ) are Microsoft Specification.
    > Some functions are not the same as Mac OSX and Linux have.

    So don't use MS specific functions when you want to write cross-
    platform code.

    > C++ iostream library uses some C Run-Time library functions such as
    > file management. It only has open() and close(), but it does not have
    > additional file functions such as rename, delete, display directory,
    > change file size, etc.


    The C standard library doesn't have the last two, either. They're
    platform specific extensions.

    > The file management in C++ iostream library has limited error
    > reporting message. The error message tells that file can’t be opened,
    > but it does not specify more details such as disk is full or file is
    > corrupted or file does not exist.

    Agreed. IMHO, the C++ standard library should set errno, much as
    stdio does.

    > Do you suggest to use both C Run-Time library and C++ iostream
    > library when you want to write your code to work all platforms? C Run-
    > Time library should have full error reporting management from all
    > operating systems.
     
    red floyd, Apr 10, 2010
    #2
    1. Advertising

  3. Immortal Nephi

    James Kanze Guest

    On Apr 10, 5:20 pm, Immortal Nephi <> wrote:
    > C Run-Time Library has most functions available to all
    > platforms such as Windows, Mac OSX, and Linux. Some functions
    > start one underscore before function name ( _funcname() ) are
    > Microsoft Specification. Some functions are not the same as
    > Mac OSX and Linux have.


    What is meant by "the C run-time library" depends somewhat on
    context. In a discussion of the language, I would presume it to
    mean "the library functions defined in the C standard". In a
    more general context, I use the term for libc.so or its
    equivalent under Windows: a library which contains a lot of
    functions which are not standard C, and at least under Unix,
    doesn't include all of the standard C library functions. (Some
    are in libm.so.)

    From what you say, I presume you mean this latter meaning. In
    which case, the libraries are very different from one platform
    to the other. For any discussion of this, you really should ask
    in a newsgroup specific to the platform.

    > C++ iostream library uses some C Run-Time library functions
    > such as file management.


    The C++ iostream library (at least filebuf and the istream and
    ostream which use it) are defined in terms of the C library.

    > It only has open() and close(), but it does not have
    > additional file functions such as rename, delete, display
    > directory, change file size, etc.


    It has rename and delete (called remove). There's no portable
    way of reading a directory, short of using a third party library
    (e.g. Boost), and there are, or at least were, systems where the
    only way of changing the file size is writing data to the end of
    it. (This was the case in early Unix, which explains why the
    standard didn't require it: there was no way they were going to
    standardize a C language which couldn't be implemented under
    Unix.)

    > The file management in C++ iostream library has limited error
    > reporting message. The error message tells that file can’t be
    > opened, but it does not specify more details such as disk is
    > full or file is corrupted or file does not exist.


    This is a general problem in C and in C++ (certainly
    conditionned by the fact that it is also a problem in Unix and
    Windows). There is always errno, but for the most part, the
    possible error codes are implementation defined, and will never
    be set if e.g. the read or write finally succeeds. (When
    reading from a remote file system, for example, it might be
    useful to know that the buffer had to be resent several times.)

    > Do you suggest to use both C Run-Time library and C++ iostream
    > library when you want to write your code to work all
    > platforms?


    As far as possible. In practice, server software will probably
    only be able to use filebuf for less important aspects, like
    logging. (Filebuf has no facilities for synchronized writing.)

    > C Run-Time library should have full error reporting
    > management from all operating systems.


    They do, via errno. But it's limited, and it's very
    implementation dependent. (Necessarily, since different OS's
    report errors differently.)

    --
    James Kanze
     
    James Kanze, Apr 11, 2010
    #3
  4. Immortal Nephi

    James Kanze Guest

    On Apr 10, 9:11 pm, Juha Nieminen <> wrote:
    > On 04/10/2010 08:59 PM, red floyd wrote:


    > > Agreed. IMHO, the C++ standard library should set errno, much as
    > > stdio does.


    > You mean it doesn't? I have always assumed it does, and it has worked
    > so far.


    The C++ standard defines file access in terms of stdio.h, so you
    get whatever is guaranteed there. (But I don't have my C
    standard available here to see exactly what that is.)

    --
    James Kanze
     
    James Kanze, Apr 11, 2010
    #4
  5. Immortal Nephi

    red floyd Guest

    On Apr 11, 5:11 am, James Kanze <> wrote:
    > On Apr 10, 9:11 pm, Juha Nieminen <> wrote:
    >
    > > On 04/10/2010 08:59 PM, red floyd wrote:
    > > > Agreed.  IMHO, the C++ standard library should set errno, much as
    > > > stdio does.

    > > You mean it doesn't? I have always assumed it does, and it has worked
    > > so far.

    >
    > The C++ standard defines file access in terms of stdio.h, so you
    > get whatever is guaranteed there.  (But I don't have my C
    > standard available here to see exactly what that is.)
    >


    My reading is that it defines it in "as if" terms. Is that explicit
    enough
    to set errno?
     
    red floyd, Apr 12, 2010
    #5
  6. Immortal Nephi

    red floyd Guest

    On Apr 12, 8:49 am, Pete Becker <> wrote:
    > red floyd wrote:
    > > On Apr 11, 5:11 am, James Kanze <> wrote:
    > >> On Apr 10, 9:11 pm, Juha Nieminen <> wrote:

    >
    > >>> On 04/10/2010 08:59 PM, red floyd wrote:
    > >>>> Agreed.  IMHO, the C++ standard library should set errno, much as
    > >>>> stdio does.
    > >>> You mean it doesn't? I have always assumed it does, and it has worked
    > >>> so far.
    > >> The C++ standard defines file access in terms of stdio.h, so you
    > >> get whatever is guaranteed there.  (But I don't have my C
    > >> standard available here to see exactly what that is.)

    >
    > > My reading is that it defines it in "as if" terms.  Is that explicit
    > > enough
    > > to set errno?

    >
    > Yes.
    >


    Thanks, Pete.
     
    red floyd, Apr 12, 2010
    #6
  7. Immortal Nephi

    red floyd Guest

    On Apr 12, 8:49 am, Pete Becker <> wrote:
    > red floyd wrote:
    > > On Apr 11, 5:11 am, James Kanze <> wrote:
    > >> On Apr 10, 9:11 pm, Juha Nieminen <> wrote:

    >
    > >>> On 04/10/2010 08:59 PM, red floyd wrote:
    > >>>> Agreed.  IMHO, the C++ standard library should set errno, much as
    > >>>> stdio does.
    > >>> You mean it doesn't? I have always assumed it does, and it has worked
    > >>> so far.
    > >> The C++ standard defines file access in terms of stdio.h, so you
    > >> get whatever is guaranteed there.  (But I don't have my C
    > >> standard available here to see exactly what that is.)

    >
    > > My reading is that it defines it in "as if" terms.  Is that explicit
    > > enough
    > > to set errno?

    >
    > Yes.
    >


    Thanks, Pete.
     
    red floyd, Apr 12, 2010
    #7
  8. Immortal Nephi

    Default User Guest

    "red floyd" <> wrote in message
    news:hpqea4$olm$-september.org...
    > On 4/10/2010 9:20 AM, Immortal Nephi wrote:


    >> The file management in C++ iostream library has limited error
    >> reporting message. The error message tells that file can’t be opened,
    >> but it does not specify more details such as disk is full or file is
    >> corrupted or file does not exist.

    > Agreed. IMHO, the C++ standard library should set errno, much as
    > stdio does.


    Most of the C file-handling functions, including fopen(), fread(), and
    fwrite(), are not required to set errno. Many implementations do, and
    additional requirements might be in place for POSIX.



    Brian
     
    Default User, Apr 12, 2010
    #8
    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. Lee
    Replies:
    2
    Views:
    3,274
    Charles Bailey
    May 9, 2004
  2. Jesper
    Replies:
    0
    Views:
    320
    Jesper
    Nov 1, 2004
  3. Fei Liu
    Replies:
    5
    Views:
    406
    Fei Liu
    Aug 21, 2007
  4. ABCL
    Replies:
    0
    Views:
    591
  5. amine
    Replies:
    2
    Views:
    948
    Jorgen Grahn
    Nov 24, 2008
Loading...

Share This Page