Re: I thought I understood sizeof().




"Paul Pluzhnikov" <ppluzhnikov-nsp@xxxxxxxxxxx> wrote in message
news:m33bkrxvbs.fsf@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

> "David Schwartz" <davids@xxxxxxxxxxxxx> writes:

>> On the flip side, by using 'sizeof', if 'temp' is ever changed to a
>> 'char *', the code will break horribly.

> The application will break visibly (truncating the expected output),
> rather than fail with silent/invisible/hard-to-find stack corruption
> (which would have happened if 'temp' became smaller but snprintf()
> wasn't updated). IMHO, that's a good thing.

Nonsense. You are assuming that the buffer will always be larger than
the size of a character pointer. If we're presuming a change in the size of
the buffer, smaller is also possible.

DS


.



Relevant Pages

  • How to get the PID and VID of a USB Mass Storage Device
    ... char driveName; ... memset (buffer, 0, sizeof (buffer)); ... char serialNumber; ...
    (microsoft.public.development.device.drivers)
  • Re: Integer to string conversion
    ... char buf; ... Simplest is to make the buffer static so it doesn't ... Shoudl fix the immediate errors, but does not fix any design issues. ... std::stringstream temp; ...
    (comp.lang.c)
  • Re: I thought I understood sizeof().
    ... > On the flip side, by using 'sizeof', if 'temp' is ever changed to a ... > 'char *', ... (which would have happened if 'temp' became smaller but snprintf() ... In order to understand recursion you must first understand recursion. ...
    (comp.unix.programmer)
  • Re: Size of mallocd?
    ... char *buffer; ... buffer = calloc; ... I cannot do sizeof *buffer since it would only return the ... size of the pointer type. ...
    (comp.lang.c)
  • Re: Size of mallocd?
    ... char *buffer; ... buffer = calloc; ... I cannot do sizeof *buffer since it would only return the ... size of the pointer type. ...
    (comp.lang.c)