Re: printf



Sensei wrote:
> On 2005-07-29 07:32:14 -0500, "biras" <rbiras@xxxxxxxxxxxxxx> said:
>
> > #include<stdio.h>
>
> Normal.

Maybe legal, but hopefully not "normal".
#include <stdio.h> is much preferred.

> > void main( )
>
> int main() as sombody said *very* correctly.

What's wrong with int main (void) ?

> > {
> > char *p;
> > p="yes";
>
>
> You are *really* lucky it didn't crash. You are writing into a random
> portion of memory.

First off, this is perfectly fine, would you also object to char *p =
"yes"? If not, what do you think the difference is between the two?

Secondly, I think you would be lucky if writing to a "random portion of
memory" *did* crash your program, there are far worse things that could
happen like not realizing that there is a problem (which there isn't in
this case).

> > printf(p);
>
>
> You still have to allocate p.

p has been allocated, what do you think the definition did? Do you
mean the space to which p points has not been allocated? If so, that
is also incorrect.

>
> > }
> >
> > output : yes
> > how printf is giving output ?
>
>
> By luck now. If you correct the errors, by calling your OS syscalls.

I think you need to crack open your C book before trying to correct
someone again ;)

Robert Gamble

.



Relevant Pages

  • [PATCH] bigphysarea for 2.6.10 en 2.6.11
    ... +contineous memory for the entire runtime of Linux. ... +The big physical area is mainly managed by two functions. ... +caddr_t bigphysarea_alloc_pages(int count, int align, int priority) ... second it is not possible to allocate some memory ...
    (Linux-Kernel)
  • [RFC][PATCH 08/12] memory hotplug: sysfs and add/remove functions
    ... This adds generic memory add/remove and supporting functions ... extern int devices_init; ... +void unregister_memory_notifier ... +/* reasonably generic interface to expand the physical pages in a zone */ ...
    (Linux-Kernel)
  • [PATCH 07/11] memory hotplug: sysfs and add/remove functions
    ... This adds generic memory add/remove and supporting functions ... extern int devices_init; ... +void unregister_memory_notifier ... +/* reasonably generic interface to expand the physical pages in a zone */ ...
    (Linux-Kernel)
  • Re: Weird malloc behaviour
    ... The result, using the Large memory model, is the following: ... wondering why it takes to different segments to allocate a structure ... second BEAM_PROFILE object on the next higher segment address, ...
    (comp.lang.c)
  • [2.6 patch] drivers/video/: possible cleanups
    ... void NVLockUnlock(struct nvidia_par *par, int Lock) ... * Note, the size of the hole may change depending on how much memory you allocate to X, ... But if the Frontbuffer is overlapped, ...
    (Linux-Kernel)