Re: Division in loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 10, 2009 at 12:31 PM, Randi Botse <nightdecoder@xxxxxxxxx> wrote:
> Thanks Glynn for let me know that the void* pointer arithmetic is
> undefined, and gcc automatically cast it to char* pointer... is this
> because void* doesn't have a size?
void * or any pointer for that matter will have a size fixed based on
your platform ie... 4 for x86 and 8 for x86_64.
> im curious when i do sizeof(void*),
> my machine tell me sizeof(void*) is 4kb

That is 4 bytes and not 4KB.

> ... i thnk when i do (void* +
> 1) that's means "4 kb after void*"?....
>
> i run the code in GNOME terminal, that's means stdout connected to xterm?
>
>
> On Thu, Sep 10, 2009 at 7:46 AM, Glynn Clements
> <glynn@xxxxxxxxxxxxxxxxxx> wrote:
>>
>> Randi Botse wrote:
>>
>>> void *buffer; /* buffer, will be allocated */
>>> ...
>>
>>>        ret = read(fdp, buffer + bytes, stat.st_size - bytes);
>>
>> Pointer arithmetic on a void* is undefined. gcc allows this as an
>> extension, treating void* like char*, i.e. p+i is treated as
>> (void*)((char*)p+i).
>>
>> For portability, define buffer as a char*.
>>
>>>        printf("\rcompleted: %i%%", progress); /* NO OUTPUT, UNTIL LOOP ENDED */
>>>        fflush(stdout);
>>
>>> Then i see printf() never output the message until the loop has ended...
>>> 'fdp' is a file descriptor to a local file, i send it through a serial
>>> connection (RS232),
>>
>> Try checking the return value of printf() and fflush(), and errno upon
>> error.
>>
>> Also, what is stdout connected to? A VT? An xterm? sshd?
>>
>> --
>> Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx>
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>



-- 
Thanks -
Manish
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux