I have one question regarding compatibility of long (32bit system) and Ulong_t64 when importing from a Tree and using an external compiler without using a generated dictionary.
Would following example work correctly?
[code]TTree* sometree = new TTree(“whatsoever”,“Testtree”);
This will work when reading on a 64 bits machine, but not on 32 bits.
I do not understand why you do not want to declare the variable as ULong64_t when reading! you do not need any dictionary to do it. I am probably missing something.
Thank you for your quick answer. I have a big pile of C code which I am reusing which utilises a lot of structs with a lot of data type long. So I only wondered if I can save some time. But I will redeclare all of the long variables to ULong64_t now.
I have one more small question.
There is no problem if I do …
[code]ULong64_t test1;
unsigned long test2;
test1 = (ULong64_t)test2;[/code]
or is there?
Because I am reading in a 32bit binary file and have to use a struct which contains unsigned longs. Or should I use ULong_t to be able to also read the 32bit binary file on a 64 bit system? If this is possible at all.
Thank you very much for all your time. I really appreciate it.
No, this will not work.
The best you can do is to change your declaration to unsigned long long if you work on a Linux machine,
but this declaration is not portable (eg on Windows, but may be you don’t care.
Okay. But if I read in the data on 32 bit system then the code in the last post would work, or am I wrong again?
I would only typecast the unsigned long into a ULong64_t to be able to insert the data into a Tree. Or is it impossible to typecast an unsigned long into a ULong64_t?
I understand that the code in my first post won’t work. But why won’t the typecast itself not work? Perhaps it is a silly question and I am getting a lot wrong. Isn’t it possible to store a long in Long64_t?
long b;
Long64_t a = (Long64_t)b;
But how should I read in data of a 32 bit binary which contains “long” and how should I handle it to add it to a Tree? Because I have to use “long” to read it out of the binary file. Do you have an ideas?
Thank’s again.
if your original data is a 32 bit unsigned integer, declare it as “unsigned int”. This is a portable type and it will work OK on 32 and 64 bits machines.
Please note that if instead of using the leaflist technique of branch creation you were to generate a dictionary for the struct and use the object technique of branch creation then I/O would be able to do schema evolution to and from any of the numerical type. However you still need to be careful since reading a 64 bits number into a 32 bits variable might/will still lead to truncation. So you are still better of making sure to use a portable type.