Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Use both C/C++ library?

Reply
Thread Tools

Use both C/C++ library?

 
 
Immortal Nephi
Guest
Posts: n/a
 
      04-10-2010
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.
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      04-10-2010
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.


 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      04-11-2010
On Apr 10, 5:20 pm, Immortal Nephi <(E-Mail Removed)> 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
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      04-11-2010
On Apr 10, 9:11 pm, Juha Nieminen <(E-Mail Removed)> 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
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      04-12-2010
On Apr 11, 5:11*am, James Kanze <(E-Mail Removed)> wrote:
> On Apr 10, 9:11 pm, Juha Nieminen <(E-Mail Removed)> 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?


 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      04-12-2010
On Apr 12, 8:49*am, Pete Becker <(E-Mail Removed)> wrote:
> red floyd wrote:
> > On Apr 11, 5:11 am, James Kanze <(E-Mail Removed)> wrote:
> >> On Apr 10, 9:11 pm, Juha Nieminen <(E-Mail Removed)> 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.
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      04-12-2010
On Apr 12, 8:49*am, Pete Becker <(E-Mail Removed)> wrote:
> red floyd wrote:
> > On Apr 11, 5:11 am, James Kanze <(E-Mail Removed)> wrote:
> >> On Apr 10, 9:11 pm, Juha Nieminen <(E-Mail Removed)> 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.
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      04-12-2010

"red floyd" <(E-Mail Removed)> wrote in message
news:hpqea4$olm$(E-Mail Removed)-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


 
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
compilation error: file exists in both in both 'c:\WINNT\Microsoft.NET\Framework\v2.0.50727 ABCL ASP .Net 0 05-29-2008 04:59 PM
2 computers, both online, both invisible to each other ? b Computer Support 9 04-21-2006 04:06 AM
Ability to use both diverse links SKhan3 Cisco 1 03-15-2005 09:23 AM
use both static and nat Nikos 'paranic' Parastatidis Cisco 3 08-31-2004 02:40 PM
Can use both VB and Javascript in same asp.net page??? KathyB ASP .Net 1 07-02-2003 12:36 AM



Advertisments