> > > [mrsam@ny mrsam]$ cat t.c
> > > #include <stdio.h>
> > >
> > > char buf[8192];
> > >
> > > int main(int argc, char **argv)
> > > {
> > > int i;
> > > char *p;
> > >
> > > memset(buf, 0, sizeof(buf));
> > >
> > > p=buf;
> > > for (i=0; i<sizeof(buf); i++)
> > > *p++=0;
> > >
> > > write(1, sizeof(buf), 1);
> > > return (0);
> > > }
> >
> > (Did you try running this program - the second param
> > to write should be an address, not a size_t)?
>
> Perhaps you haven't noticed the time() output, right there in the middle
> of my post.
I did. It's way too small to indicate anything but noise.
On Solaris an empty program issues some 19 system calls including
2 opens. A write() of 1 byte surely gets lost in the noise.
Here's a truss of your program without any code between main() and the
return.
execve("x", 0x08047474, 0x0804747C) argc = 1
mmap(0x00000000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0) =
0xDFBC0000
xstat(2, "x", 0x08047214) = 0
sysconfig(_CONFIG_PAGESIZE) = 4096
open("/usr/lib/libc.so.1", O_RDONLY) = 3
fxstat(2, 3, 0x08047068) = 0
mmap(0x00000000, 4096, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xDFBB0000
mmap(0x00000000, 651264, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xDFB00000
munmap(0xDFB87000, 65536) = 0
mmap(0xDFB97000, 22296, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3,
552960) = 0xDFB97000
mmap(0xDFB9D000, 4156, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANON,
-1, 0) = 0xDFB9D000
close(3) = 0
open("/usr/lib/libdl.so.1", O_RDONLY) = 3
fxstat(2, 3, 0x08047068) = 0
mmap(0xDFBB0000, 4096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0xDFBB0000
close(3) = 0
sysi86(SI86FPHW, 0xDFB9DFD8, 0x08047430, 0xDFBFA000) = 0x00000000
llseek(0, 0, SEEK_CUR) = 334465
llseek(0, 0, SEEK_CUR) = 334465
_exit(0)
And here's a truss with your code intact. Spot the difference:
execve("x", 0x08047474, 0x0804747C) argc = 1
mmap(0x00000000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0) =
0xDFBC0000
xstat(2, "x", 0x08047214) = 0
sysconfig(_CONFIG_PAGESIZE) = 4096
open("/usr/lib/libc.so.1", O_RDONLY) = 3
fxstat(2, 3, 0x08047068) = 0
mmap(0x00000000, 4096, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xDFBB0000
mmap(0x00000000, 651264, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xDFB00000
munmap(0xDFB87000, 65536) = 0
mmap(0xDFB97000, 22296, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3,
552960) = 0xDFB97000
mmap(0xDFB9D000, 4156, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANON,
-1, 0) = 0xDFB9D000
close(3) = 0
open("/usr/lib/libdl.so.1", O_RDONLY) = 3
fxstat(2, 3, 0x08047068) = 0
mmap(0xDFBB0000, 4096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0xDFBB0000
close(3) = 0
sysi86(SI86FPHW, 0xDFB9DFD8, 0x08047430, 0xDFBFA000) = 0x00000000
write(1, "\0", 1) = 1
llseek(0, 0, SEEK_CUR) = 335418
llseek(0, 0, SEEK_CUR) = 335418
_exit(0)
> If you've actually cared enough to examine the putc macros, you would've
> observed that's how it works, and this was only an attempt to emulate
> putc()'s implementation as closely as possible.
>
> > What exactly are you trying to compare here?
>
> Prove the obvious to people who, for some reason, refuse to accept it.
Perhaps then you should be sure of what you're measuring...
Regards.