|
From: Per W. <pw...@ia...> - 2003-07-09 07:06:44
|
See below
/Per W
On Wed, 9 Jul 2003, Neszt Tibor wrote:
> Hello!
>
> I have a problem. First of all, see the source code:
>
>
> This one is works:
> /* -------------------------------------------------------------------- */
> int putbuffer( /* returns 0 on success */
> void *AppState,
> unsigned char *buffer, /* buffer to put */
> long length /* length of buffer */
> ) {
> size_t ret;
>
> crc = CrcUpdate(crc, buffer, length);
>
> ret = fwrite(buffer, 1, (size_t) length, (FILE *) AppState);
>
> if ((size_t) length != ret)
> return 1;
> else
> return 0;
> }
>
>
>
>
> I tried to change it to work in memory instead of writing to file:
>
> /* -------------------------------------------------------------------- */
> int putbuffer_mem( /* returns 0 on success */
> void *AppState,
> unsigned char *buffer, /* buffer to put */
> long length /* length of buffer */
> ) {
> int i;
unsigned char *tmpptr = (unsigned char*)AppState;
>
> crc = CrcUpdate(crc, buffer, length);
>
> for (i=0;i<length;i++) {
// Here you declare a NEW variable AppState completely different
// from the parameter you sent in. Of course AppState++ doesn't
// do anything since the compiler is clearly aware that you don't
// use this new variable outside of the loop.
// Besides - you can't increment a void* pointer since it doesn't
// point to a data type of a known size.
> char *AppState=buffer[i]; // #1
> AppState++; // #2
tmpptr[i] = buffer[i];
// or *tmpptr++ = *buffer++;
> printf("a\n");
> }
> return 0;
> }
>
> This second one does nothing as I check the AppState.
> Can I use (void *) to allocate memory?
> The original call was
>
> putbuffer( (void *) out, .....) ( out = fopen("name", "wb"); )
>
>
> And now, I call
>
> putbuffer_mem( mem, ....) ( mem = (char *) malloc(size); )
>
>
> What would be the problem?
>
> Is there any mode to mix the #1 and the #2 lines?
>
>
> Thanks Your help in advance.
>
> Regards,
> Neszt Tibor
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Parasoft
> Error proof Web apps, automate testing & more.
> Download & eval WebKing and get a free book.
> www.parasoft.com/bulletproofapps
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|