Problem of compilation

Hello everybody

I have got a problem when I try to compile a tool called netmate-0.9.5 which is written in C. Here is the following error, I get :

1
2
3
4
 
../../src/netmate/MetricData.h:101:34: error: cast from 'char*' to 'unsigned int' loses precision [-fpermissive]
      (char*) (((unsigned int)(var) + DataTypeSize[type]-1) 


I don't know very well the C language. I have tried to modify the line which launches an error as follows :

1
2
(char*) ((atoi(var) + DataTypeSize[type]-1)


This time the programm compiles, however when I execute the programm there is a "core dump". I don' know what to do.
By the way, I have got a 64 bits os (ubunutu 14.04) ? How can I solve this problem ? And if I don't succed in solving this problem, can somebody advice me another tool which can compute the metrics of a pcap file as easily as netmate.

Thanks in advance for any answer

I apologize for my bad english, it is not my native language.
It is really bad and old C code which will probably break on any 64bit PC. I do not know why it is done like that, but you may try to remove casts altogether: (var + DataTypeSize[type]-1)
I have tried to replace the code as you have advised. Thus, instead of
1
2
(char*) (((unsigned int) (var) + DataTypeSize[type]-1) /
		     DataTypeSize[type] * DataTypeSize[type]);

I have
1
2
(char*) ((var + DataTypeSize[type]-1) /
		     DataTypeSize[type] * DataTypeSize[type]);


When I try to compile, I have got this time the following error :

../../src/netmate/MetricData.h:102:25: error: invalid operands of types 'char*' and 'short unsigned int' to binary 'operator/'
DataTypeSize[type] * DataTypeSize[type]);

It does not like that I divise a char* with a short unsigned int. Any idea to overcome this pb.


Thanks in advance
Ok, I got it, it tries to align values. For quick fix, you can try replacing cast to unsigned int with cast to uintptr_t. Do not forget to include <stdint.h>
Great !!! It is solved. But what does it mean to align values ?
And you are right because the name of the function which uses this code is called inline char *align(char *var, DataType_e type)
what does it mean to align values ?

http://en.wikipedia.org/wiki/Data_structure_alignment
Topic archived. No new replies allowed.