4 layer reference model for communication error
I'm trying to simulate a simple 4 layer reference model for communication between two hosts. However, I seem to be getting a simple error, which I can't figure out.
The Part of my code is:
Code:
int* layer2(int* buf,int* bufsize, int flag)
{
if(flag == 1) //Transmit
{
int packetnum = 1;
if(bufsize[0] > MAXDATA)
{
double x = (((double)bufsize[0])/MAXDATA);
packetnum = ceil(x);
}
And the following error I'm getting refers to packetnum = ceil(x);
[Warning] converting to `int' from `double'
Re: converting double to int
I tried your sample code with my sample inputs. It doesn't give any error or warning.
Normally C will handle this automatic type conversion. ( double to int )
Code:
#include<stdio.h>
#include<math.h>
int* layer2(int* buf,int* bufsize, int flag)
{
if(flag == 1) //Transmit
{
int packetnum = 1;
if(bufsize[0] > 10)
{
double x = (((double)bufsize[0])/10);
packetnum = ceil(x);
printf("packet:%d",packetnum);
}
}
}
int main()
{
int buf[]={1,2,3};
int bufsize[]={25,30,40};
layer2(buf,bufsize,1);
return 0;
}