![]() |
| ||
| problem with size_t filesize Hello I have little problem with a code. I want to send information about a size on a file and uses “size_t filesize”. I will send this information thru a network called ”controller area Network” and uses the code stat = canWrite(hnd, 1234, size, 8, canMSG_EXT); in order to do this. The problem is that ”size” in the code only may last 8 byte. Is there somewhat better way to type the code below? void send_messege(void) |
| ||
| Re: problem with size_t filesize >>stat = canWrite(hnd, 1234, size, 8, canMSG_EXT); what is the 1234 and 8 for? sizeof(size_t), which is an unsigned int, if 4 on most 32-bit computers, not 8. |
| ||
| Re: problem with size_t filesize >Is there somewhat better way to type the code below? Are you simply asking for advice on working code, or are you having problems with it? I can see areas where mixing and matching types (both ranges and signedness) may get you in trouble. If all you want is ways to improve the code then to simplify matters, I would get rid of data and just use a slice of buf: for ( i = 0; i < filesize; i += 8 ) {And you can refactor that while writing piece because everything is the same except for the pointer to your eight bytes:int networkWrite ( unsigned char *start )Then the two blocks of code become: /* Send away INFO about the file's size */However, since size is an unsigned int, you have an issue if int isn't an 8-byte quantity. If that's the case, you need to pad it. The same goes for if the file size isn't evenly divisible by eight. You can bring data back into the picture for this: /* Send away INFO about the file's size */Beyond that you'll have to specify what you need help with. |
| ||
| Re: problem with size_t filesize Hello again. Thanks a lot for these codes. They have helped a lot. I have typed 2 codes, one in order to send a file via controller area Network and a code in order to receive the file. However, there are 2 problems with the code in order to receive the file. 1: Stack around the variable buf was corrupted 2: I believe that the file that to be sent is ok, but when I receive the file and then saved it on the hard disk. It has same size that the original file. But it is corrupted. Some proposals on how to solve this? The code to send the file #include <stdlib.h> And the code to receive #include <stdlib.h> |
| ||
| Re: problem with size_t filesize >> Stack around the variable buf was corrupted That means the program has trashed the stack somewhere. That's a tough one to find. Check for buffer overruns, writing beyond the end of a buffer or array, using uninitialized pointers, and indexing into non-existant array elements. If you still can't find it then start commenting out blocks of code until the problem disappears. When that happens you have probably found the deamon. |
| All times are GMT -4. The time now is 6:03 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC