Re: fstream on linuxx8664gcc platform

From: Masaharu Goto <gotom_at_hanno.jp>
Date: Wed, 18 May 2005 16:35:13 +0900


Hello Kerry,

After a while, I come to think that such usage of tellg() and pos_type may not be allowed in C++. It happened to work on ICC but the code is not portable. Since file size may be beyond the size of long int. And pos_type may contain larger number than long int can handle. Hence, conversion from pos_type to long int is not defined in C++. The number you get from tellg() in g++ is an address of pos_type object.

This is my conclusion, but tell me if I am wrong. If there is a standardized conversion from pos_type to long int, I can add that interface to gcc3strm.cxx.

Thank you
Masa Goto

On 2005/05/18, at 10:25, LEE, KERRY T. (JSC-SF) (UHCL) wrote:

>
> I found out that if I cut out this piece of code that reads the file
> and
> make it a seperate function, then compile it with ACLIC, fstream works
> fine.
> This is not so elegant code but it works. I will be looking forward
> to a
> more permanent fix from Masa and Philippe.
>
> Thanks
> Kerry
>
> -----Original Message-----
> From: Fons Rademakers
> To: LEE, KERRY T. (JSC-SF) (UHCL)
> Cc: '''roottalk_at_pcroot.cern.ch' ' '; ''Masaharu Goto ' '; ''Philippe
> Canal '
> '
> Sent: 5/17/2005 4:48 PM
> Subject: Re: [ROOT] fstream on linuxx8664gcc platform
>
> There is not directly a workaround for this. I hope Masa and Philippe
> will
> look into this (and the other stream problem).
>
> Cheers, Fons.
>
>
>
> LEE, KERRY T. (JSC-SF) (UHCL) wrote:
>> Hi Fons,
>>
>> Thanks for this workaround.
>>
>> There is another place in my code where I do the following:
>>
>> fstream fff("mntExHdd",ios_base::in|ios_base_out);
>> ....
>> Do some reading of the file
>> ...
>> fff.tellg();
>>
>> This last line reports a wrong number just like the size was
> incorrect. Is
>> there also a portable way in ROOT to work around this problem?
>>
>> Thanks
>> Kerry
>>
>>
>> -----Original Message-----
>> From: Fons Rademakers
>> To: LEE, KERRY T. (JSC-SF) (UHCL)
>> Cc: ''roottalk_at_pcroot.cern.ch' '; 'Masaharu Goto '; 'Philippe Canal '
>> Sent: 5/14/2005 2:30 AM
>> Subject: Re: [ROOT] fstream on linuxx8664gcc platform
>>
>> Hi Kerry,
>>
>> this will give you file sizes in a portable way in ROOT:
>> #include <TSystem.h>
>> FileStat_t s;
>> gSystem->GetPathInfo("mntExHdd", s)
>> s.fSize // contains the size
>>
>>
>> -- Fons
>>
>>
>> LEE, KERRY T. (JSC-SF) (UHCL) wrote:
>>
>>>
>>> Hi Fons,
>>>
>>> In the meantime, do you know of a workaround I can use to get the
>>> file
>>
>> size?
>>
>>> Thanks
>>> Kerry
>>>
>>> -----Original Message-----
>>> From: Fons Rademakers
>>> To: LEE, KERRY T. (JSC-SF) (UHCL)
>>> Cc: 'roottalk_at_pcroot.cern.ch'; Masaharu Goto; Philippe Canal
>>> Sent: 5/13/2005 7:29 PM
>>> Subject: Re: [ROOT] fstream on linuxx8664gcc platform
>>>
>>> Hi Kerry,
>>>
>>> I see the same problem on my AMD64. Looks like a CINT issue. I'll
>>> forward
>>> it to Masa.
>>>
>>> Cheers, Fons.
>>>
>>>
>>>
>>> LEE, KERRY T. (JSC-SF) (UHCL) wrote:
>>>
>>>
>>>> Dear Root Team,
>>>>
>>>> I have transferred some code from a linuxicc platform ROOT version
>>>
>>> 4.02/00
>>>
>>>
>>>> to linuxx8664gcc ROOT version 4.04/02 and it crashed due to
>>>> incorrect
>>>> determination of the filesize using fstream. Here is a sample code
>>>
>>> that
>>>
>>>
>>>> reproduces the problem, where you just put a file in ascii format in
>>>
>>> place
>>>
>>>
>>>> of "mntExHdd". The correct filesize in my case is 105bytes.
>>>>
>>>> //TestStream.C
>>>> {
>>>> TString FileName="mntExHdd";
>>>> fstream fff(FileName,ios_base::in);
>>>> if(fff.good()){
>>>> fff.seekg(0,ios_base::end);
>>>> int FileSize = fff.tellg();
>>>> cout<<"FileSize="<<FileSize<<endl;
>>>> fff.seekg(0,ios_base::beg);
>>>> }
>>>> fff.close();
>>>> }
>>>>
>>>> The results from linuxicc
>>>>
>>>> *******************************************
>>>> * *
>>>> * W E L C O M E to R O O T *
>>>> * *
>>>> * Version 4.02/00 17 December 2004 *
>>>> * *
>>>> * You are welcome to visit our Web site *
>>>> * http://root.cern.ch *
>>>> * *
>>>> *******************************************
>>>>
>>>> FreeType Engine v2.1.3 used to render TrueType fonts.
>>>> Compiled for linuxicc with thread support.
>>>>
>>>> CINT/ROOT C/C++ Interpreter version 5.15.159, Nov 14 2004
>>>> Type ? for help. Commands must be C++ statements.
>>>> Enclose multiple statements between { }.
>>>> root [0] .x TestStream.C
>>>> FileSize=105
>>>>
>>>>
>>>> The Results from linuxx8664gcc
>>>>
>>>> *******************************************
>>>> * *
>>>> * W E L C O M E to R O O T *
>>>> * *
>>>> * Version 4.04/02 9 May 2005 *
>>>> * *
>>>> * You are welcome to visit our Web site *
>>>> * http://root.cern.ch *
>>>> * *
>>>> *******************************************
>>>>
>>>> Compiled for linuxx8664gcc with thread support.
>>>>
>>>> CINT/ROOT C/C++ Interpreter version 5.15.169, Mar 14 2005
>>>> Type ? for help. Commands must be C++ statements.
>>>> Enclose multiple statements between { }.
>>>> root [0] .x TestStream.C
>>>> FileSize=7470896
>>>>
>>>>
>>>>
>>>>
>>>> Thanks
>>>> Kerry
>>>
>>>
>>
>
> --
> Org: CERN, European Laboratory for Particle Physics.
> Mail: 1211 Geneve 23, Switzerland
> E-Mail: Fons.Rademakers_at_cern.ch Phone: +41 22 7679248
> WWW: http://www.rademakers.org/fons/ Fax: +41 22 7679480
>
Received on Wed May 18 2005 - 13:20:11 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:08 MET