ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
"dereferencing pointer to incomplete type"....what is the meaning of this?anybody?
i'm compiling these source code....and its appear liked below....
(the code)
/*
* Format the data and write it out to the output file
*/
tm_ptr = localtime( (time_t *)&data.time_tag.tv_sec );
switch( data.data_type )
{
case INTEGER_TYPE:
(163) fprintf(out_file,"%02d:%02d:%02d.%06d -- %d -- %d\n", tm_ptr->tm_hour, tm_ptr->tm_min,tm_ptr->tm_sec, data.time_tag.tv_usec, data.seq_num, data.raw_data.int_value);
break;
case FLOAT_TYPE:
(166) fprintf(out_file,"%02d:%02d:%02d.%06d -- %d -- %f\n", tm_ptr->tm_hour, tm_ptr->tm_min,tm_ptr->tm_sec, data.time_tag.tv_usec, data.seq_num, data.raw_data.float_value);
break;
default:
fprintf(stderr,"Recevied invalid packet type!\n");
}
(the error)
ams@lan ex7]$ gcc -c dataSink.c
dataSink.c: In function `main':
dataSink.c:159: warning: assignment makes pointer from integer without a cast
dataSink.c:163: dereferencing pointer to incomplete type
dataSink.c:163: dereferencing pointer to incomplete type
dataSink.c:163: dereferencing pointer to incomplete type
dataSink.c:166: dereferencing pointer to incomplete type
dataSink.c:166: dereferencing pointer to incomplete type
dataSink.c:166: dereferencing pointer to incomplete type
It looks that line 159 is the localtime call. Are you sure tmp_ptr is really struct tm * ? There's problem with this or data is not what it should. Check also headers to see if you include all that's needed.
/*
* Local header files
*/
#include "serialLib.h"
#include "dataFormat.h"
/*
* This is the input device, it is machine dependent and probably will need
* to be changed depending upon what machine you are on.
*
* Linux: /dev/ttyS1
* AIX: /dev/
* SunOS: /dev/
* Lynx: /dev/
*/
#define INPUT_DEVICE "/dev/ttyS1"
/*
* The main program
*/
int main( int argc, char *argv[] )
{
/*
* The time structures
*/
struct timeval start_time;
struct timeval end_time;
/*
* The data packet buffer and data
*/
data_t data;
char *buffer = (char *)&data;
/*
* The file pointer were the data will be written to
*/
FILE *out_file;
/*
* Miscellaneous variables
*/
int fp;
int i = 0;
int size;
struct tm *tm_ptr;
int bytes;
int total_bytes = 0;
/*
* Open the serial port using the serialLib calls. Note that for the
* reader, blocking I/O is used.
*/
if( (fp = serialOpen(INPUT_DEVICE, O_RDONLY)) == -1 )
{
exit(1);
}
/*
* Open the output file were the results will be written to
*/
if( (out_file = fopen( "out.file", "w" )) == (FILE *)NULL )
{
fprintf(stderr,"Could not open output file!\n");
serialClose(fp);
exit(1);
}
/*
* Get the start time of the processing
*/
gettimeofday(&start_time,NULL);
/*
* Loop for the number of packets expected
*/
while( i < NUM_OF_PACKETS )
{
/*
* The following sequence of code will read exactly one data packet
* from the serial port. Since the read statement will not always
* return the exact size of the packet, additional steps must be taken
* to be sure that a complete packet is read.
*
* First, the number of bytes read is initialized to zero. As long
* as the number of bytes read is less than the size of the data
* structure, a read will be performed. The number of bytes to read
* is simple the number of bytes read thus far (bytes) subtracted from
* the number of bytes in a packet (sizeof(data_t)). Each time a read
* is completed, the number of bytes read (size) is added to the bytes
* read (bytes). This continues until the packet is read from the
* serial port.
*/
bytes = 0;
while( bytes < sizeof(data_t) )
{
if( (size = read( fp, buffer + bytes, sizeof(data_t) - bytes)) == -1 )
{
perror("read failed");
serialClose(fp);
exit(1);
}
bytes += size;
}
total_bytes += bytes;
/*
* Verify that the sequence number in the packet matches the sequence
* number that is expected.
*/
if( data.seq_num != i )
{
fprintf(stderr,"Sequence number mismatch, current: %d -- recevied: %d\n", data.seq_num, i );
fprintf(stderr,"Adjusting sequence number to recieved value!\n");
i = data.seq_num;
}
/*
* Format the data and write it out to the output file
*/
tm_ptr = localtime( (time_t *)&data.time_tag.tv_sec );
switch( data.data_type )
{
case INTEGER_TYPE:
fprintf(out_file,"%02d:%02d:%02d.%06d -- %d -- %d\n", tm_ptr->tm_hour, tm_ptr->tm_min,
tm_ptr->tm_sec, data.time_tag.tv_usec, data.seq_num, data.raw_data.int_value);
break;
case FLOAT_TYPE:
fprintf(out_file,"%02d:%02d:%02d.%06d -- %d -- %f\n", tm_ptr->tm_hour, tm_ptr->tm_min,
tm_ptr->tm_sec, data.time_tag.tv_usec, data.seq_num, data.raw_data.float_value);
break;
default:
fprintf(stderr,"Recevied invalid packet type!\n");
}
/*
* Increment the number of packets received and complete the loop
*/
i++;
}
/*
* Get the ending time
*/
gettimeofday(&end_time,NULL);
/*
* Close the serial port
*/
serialClose(fp);
/*
* Close the output file
*/
fclose(out_file);
/*
* Calculate some statistics based on the data collected
*/
printf("----- Reciever -----\n");
printf("Total Packets: %d\n", i );
printf("Total Bytes Received: %d\n", bytes );
printf("Interval: %0.6f\n",
((float)(end_time.tv_sec - start_time.tv_sec) +
((float)(end_time.tv_usec - start_time.tv_usec)/1000000)));
printf("Data Rate: %0.6f\n",
((float)(i * sizeof(data_t))) /
((float)(end_time.tv_sec - start_time.tv_sec) +
((float)(end_time.tv_usec - start_time.tv_usec)/1000000)));
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.