TString to Long64_t conversion

Hi

Is exist function in ROOT, which provide conversion
of TString to Long64_t for all platforms and compilers?

On 64-bit machine I can use standard C function:

long atol(const char*)

but on 32-bit machnie it does not work with 64-bit integers.

I can use sscanf() in the way like:

Long64_t res = 0;
sscanf(“109876543210”,"%lld",&res);

But this does not work on all platforms.
For Visual C++ I should use other argument:

sscanf(value,"%I64d",&res);

Actually, for 64 bit platforms I should use “%ld”.

It can be nice to have TString:Atol() and TString:Atol64() methods,
which takes into account all this variations.

Regards,
Sergey Linev

Do, eg

root > Long64_t = 123456789; root > TString s="sergey_" root > s += l
Rene

Hi, Rene

What you proposed, is conversion from Long64_t to const char*.
I need another direction: from const char* to Long64_t.

Actually, I found usage of “%lld” formating string in several places in ROOT.
For example, in “longif.h”, “longif3.h” and “longlong.h” in CINT as sscanf() arguments, which can not work for VC++.

Sergey

Sorry, I misunderstood your question.
We have TString::Atoi. We could implement AtoL.

Note that you can use sscanf. %lld works on Windows, but only
with VC++7.1 on newer. We do not support anymore the old compilers
VC++6 or VC++7.0

Rene

I using VC++ 7.1.
"%lld" only working in one direction: from long long to const char* in printf(),
but not from const char* to long long in sscanf().

Actually, it can be usefull to make several definitions like:

#define FmtLong64_t “%lld”
#define FmtULong64_t “%llu”

and so on for other ROOT basic types.

I use such definitions in TBufferSQL2 & TBufferXML for conversions
of basic types from/to const char* and the same definitions can be used
as arguments in printf()/scanf() functions calls.

Hi,

Actually on VC7, as far as I know, “%lld” works is neither direction. Instead VC7 use “%I64d”

Cheers,
Philippe

I also was suprised, but my small test programs show that
printf("%lld") works in VC++ 7.1, but scanf("%lld") does not.
I look MS website. In no places I found %lld description.

Anyway, “%I64d” is better to use in all situation with Windows.