PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > streams - c standard
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
streams - c standard

Réponse
 
LinkBack Outils de la discussion
Vieux 22/10/2007, 10h31   #1
MisterE
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut streams - c standard

Is there anything in c standard about the operation of file streams etc. in
reguards to how they are supposed to act if an over flow occurs. I am trying
to work out the correct way to handle files that are greater than 2^32
bytes. Different compilers/operating systems etc. all behave different for
ftell. I guess the answer is its undefined...


  Réponse avec citation
Vieux 22/10/2007, 12h51   #2
Richard Bos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: streams - c standard

"MisterE" <MisterE@nimga.com> wrote:

> Is there anything in c standard about the operation of file streams etc. in
> reguards to how they are supposed to act if an over flow occurs.


No. Except, of course, that merely writing to a file which is about to
"overflow" (quotes because it's not the same thing as a real numeric
overflow) may continue to write properly; may write garbage (since no
conforming program can detect the difference anyway); may return with an
error status as it would for, say, a file without write access; but may
_not_ crash the program, return nonsense, or exhibit other truly
undefined behaviour.

Richard
  Réponse avec citation
Vieux 22/10/2007, 13h37   #3
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: streams - c standard

MisterE wrote:

> Is there anything in c standard about the operation of file streams
> etc. in reguards to how they are supposed to act if an over flow
> occurs.


Overflow for a file?

All that Standard C guarantees is that the various I/O functions of the
Standard library, (like putc, printf etc.), will return a status value
indicating success or failure. The variable `errno` may or may not be
set to any meaningful value.

Thus though you can detect a failed operation, it's generally difficult
or not possible with Standard C to find out _why_ the operation has
failed. You might have to depend upon implementation and system
specific methods.

> I am trying to work out the correct way to handle files that
> are greater than 2^32 bytes.


On 32 bit systems, you very probably have to use non-Standard
alternatives like ftello, ftello64 etc.

You shouldn't have a problem on 64 bit systems.

> Different compilers/operating systems
> etc. all behave different for ftell.


No. ftell behaves the way the Standard defines it. However it may or may
not be sufficient under certain conditions.

> I guess the answer is its
> undefined...


It _is_ defined. You're going beyond it's specification however, so what
do you expect?

  Réponse avec citation
Vieux 22/10/2007, 21h19   #4
Justin Spahr-Summers
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: streams - c standard

On Oct 22, 7:37 am, santosh <santosh....@gmail.com> wrote:
> MisterE wrote:
> > I am trying to work out the correct way to handle files that
> > are greater than 2^32 bytes.

>
> On 32 bit systems, you very probably have to use non-Standard
> alternatives like ftello, ftello64 etc.
>
> You shouldn't have a problem on 64 bit systems.


Isn't this at least part of the reason fgetpos() and fsetpos() exist?
fpos_t is allowed to be larger than a long, and even a non-integral
type, to handle possibly huge files.

  Réponse avec citation
Vieux 22/10/2007, 23h02   #5
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: streams - c standard

Justin Spahr-Summers wrote:

> On Oct 22, 7:37 am, santosh <santosh....@gmail.com> wrote:
>> MisterE wrote:
>> > I am trying to work out the correct way to handle files that
>> > are greater than 2^32 bytes.

>>
>> On 32 bit systems, you very probably have to use non-Standard
>> alternatives like ftello, ftello64 etc.
>>
>> You shouldn't have a problem on 64 bit systems.

>
> Isn't this at least part of the reason fgetpos() and fsetpos() exist?
> fpos_t is allowed to be larger than a long, and even a non-integral
> type, to handle possibly huge files.


Yes. I should have mentioned that. When the OP said he was using ftell,
(and encountering problems), I automatically thought of ftell-like
alternatives.

As you said, fgetpos and fsetpos are Standardised and better.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h16.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10073 seconds with 13 queries