Use both C/C++ library?

I

Immortal Nephi

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

red floyd

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

James Kanze

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.)
 
J

James Kanze

On 04/10/2010 08:59 PM, red floyd wrote:
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.)
 
R

red floyd

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?
 
D

Default User

red floyd said:
On 4/10/2010 9:20 AM, Immortal Nephi wrote:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top