468,736 Members | 2,113 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,736 developers. It's quick & easy.

fread/fwrite

How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.

May 17 '07 #1
30 13818
empriser wrote:
How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.
None.

Don't you have documentation for these functions? Or man pages? Or
access to Google?

--
"Reaching out for mirrors hidden in the web." - Renaissance, /Running Hard/

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

May 17 '07 #2
On 17 May 2007 00:52:29 -0700, empriser <xu********@gmail.comwrote:
>How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.
It depends on how code the fread. If you specify 1 block of n
characters and there is less than n left in the file, then it will
return 0. However, if you specify n blocks of 1 character each, then
it will return the number of blocks read (which will be exactly the
same as the number of characters read).
Remove del for email
May 17 '07 #3
On May 17, 8:25 pm, Barry Schwarz <schwa...@doezl.netwrote:
On 17 May 2007 00:52:29 -0700, empriser <xueyunl...@gmail.comwrote:
How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.

It depends on how code the fread. If you specify 1 block of n
characters and there is less than n left in the file, then it will
return 0. However, if you specify n blocks of 1 character each, then
it will return the number of blocks read (which will be exactly the
same as the number of characters read).

Remove del for email
Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer, after last call
fread as if return 0.

Jul 5 '07 #4
empriser wrote:
On May 17, 8:25 pm, Barry Schwarz <schwa...@doezl.netwrote:
>On 17 May 2007 00:52:29 -0700, empriser <xueyunl...@gmail.comwrote:
>>How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.
It depends on how code the fread. If you specify 1 block of n
characters and there is less than n left in the file, then it will
return 0. However, if you specify n blocks of 1 character each, then
it will return the number of blocks read (which will be exactly the
same as the number of characters read).

Remove del for email

Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer, after last call
fread as if return 0.
fread returns the number of elements that were read and
stored in the buffer. If fread returns 10, it successfully
read and stored 10 elements. If fread returns 0, it read
and stored ... <wait for it... no elements.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jul 5 '07 #5
On Thu, 05 Jul 2007 05:00:26 -0000, empriser <xu********@gmail.com>
wrote:
>On May 17, 8:25 pm, Barry Schwarz <schwa...@doezl.netwrote:
>On 17 May 2007 00:52:29 -0700, empriser <xueyunl...@gmail.comwrote:
>How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.

It depends on how code the fread. If you specify 1 block of n
characters and there is less than n left in the file, then it will
return 0. However, if you specify n blocks of 1 character each, then
it will return the number of blocks read (which will be exactly the
same as the number of characters read).

Remove del for email

Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer, after last call
fread as if return 0.
If you don't show your code, everything is just a guess. As long as
we are guessing, I guess that the number of bytes read is equal to the
square root of the address of fread (when cast to an unsigned short).
Remove del for email
Jul 6 '07 #6
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
empriser wrote:
...
Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer,
after last call fread as if return 0.

fread returns the number of elements that were
read and stored in the buffer. If fread returns 10,
it successfully read and stored 10 elements. If
fread returns 0, it read and stored ... <wait for
it... no elements.
In other words, code as...

static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);

....rather than...

static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);

Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.

--
Peter

Jul 6 '07 #7
OK I write a easy program to show it.
fread( buf, sizeof(buf), 1, rf );
fwrite( buf, sizeof(buf), 1, wf );

If I don't change to fread( buf, 1, sizeof(buf), rf ); how to copy a
file.

int main( int argc, char **argv )
{
int i;
char buf[1024];
FILE *rf, *wf;

rf = fopen( argv[1], "r" );
wf = fopen( argv[2], "w" );

i = fread( buf, sizeof(buf), 1, rf );
while( i 0 ){
fwrite( buf, sizeof(buf), 1, wf );
i = fread( buf, sizeof(buf), 1, rf );
}

fclose( rf );
fclose( wf );
return 0;
}

Jul 7 '07 #8
On Sat, 07 Jul 2007 03:04:46 -0000, empriser <xu********@gmail.com>
wrote:
>OK I write a easy program to show it.
fread( buf, sizeof(buf), 1, rf );
fwrite( buf, sizeof(buf), 1, wf );

If I don't change to fread( buf, 1, sizeof(buf), rf ); how to copy a
file.
By changing fread to fgetc and fwrite to fputc.

What is with the spate of "I've got this broken code I don't want to
change. How do I make it work?" messages. The only way to fix broken
code is to change it. It you don't change it, it remains broken.

If I insist on putting water in my gas tank, how do I get my car to
run?
>
int main( int argc, char **argv )
{
int i;
char buf[1024];
FILE *rf, *wf;

rf = fopen( argv[1], "r" );
wf = fopen( argv[2], "w" );

i = fread( buf, sizeof(buf), 1, rf );
while( i 0 ){
fwrite( buf, sizeof(buf), 1, wf );
i = fread( buf, sizeof(buf), 1, rf );
}

fclose( rf );
fclose( wf );
return 0;
}

Remove del for email
Jul 7 '07 #9
empriser wrote:
OK I write a easy program to show it.
fread( buf, sizeof(buf), 1, rf );
fwrite( buf, sizeof(buf), 1, wf );

If I don't change to fread( buf, 1, sizeof(buf), rf ); how to copy a
file.

int main( int argc, char **argv )
{
int i;
char buf[1024];
FILE *rf, *wf;

rf = fopen( argv[1], "r" );
wf = fopen( argv[2], "w" );

i = fread( buf, sizeof(buf), 1, rf );
while( i 0 ){
fwrite( buf, sizeof(buf), 1, wf );
i = fread( buf, sizeof(buf), 1, rf );
}

fclose( rf );
fclose( wf );
return 0;
}
Maybe this way..

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
FILE *in, *out;
char buf[100];
size_t size;

if ((in = fopen("cp.c", "rb")) == NULL)
puts("Can't open cp.c"), exit(EXIT_FAILURE);

if ((out = fopen("cp.x", "wb")) == NULL)
puts("Can't make cp.x"), exit(EXIT_FAILURE);

while ((size = fread(buf, 1, sizeof buf, in)) 0)
fwrite(buf, 1, size, out);

fclose(in);
fclose(out);
return 0;
}

Note that cp.c is the name of this source file.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Jul 7 '07 #10
On Jul 5, 6:42 pm, Peter Nilsson <a...@acay.com.auwrote:
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
empriser wrote:
...
Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer,
after last call fread as if return 0.
fread returns the number of elements that were
read and stored in the buffer. If fread returns 10,
it successfully read and stored 10 elements. If
fread returns 0, it read and stored ... <wait for
it... no elements.

In other words, code as...

static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);

...rather than...

static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);

Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.

--
Peter
Is size_t and all such stuffs portable in c? If not what to make it
so?
Guru Jois

Jul 8 '07 #11
Guru Jois wrote:
On Jul 5, 6:42 pm, Peter Nilsson <a...@acay.com.auwrote:
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
empriser wrote:
...
Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer,
after last call fread as if return 0.
fread returns the number of elements that were
read and stored in the buffer. If fread returns 10,
it successfully read and stored 10 elements. If
fread returns 0, it read and stored ... <wait for
it... no elements.
In other words, code as...

static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);

...rather than...

static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);

Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.

Is size_t and all such stuffs portable in c? If not what to make it
so?
size_t is defined in the Standard, so it's certainly portable. New
users to C tend to have some confusion over using size_t objects with
printf and family. Generally using the lu format specifier with a cast
to the appropriate type is recommended. If you can, and want to, use
C99's additions the zu specifier is specifically there for size_t.

Jul 8 '07 #12
Guru Jois wrote:
>
.... snip ...
>
Is size_t and all such stuffs portable in c? If not what to make
it so?
Yes. That is, in part, why this newsgroup limits the topic to
STANDARD C, and considers references to system dependent things as
being off-topic. Read the standard.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jul 8 '07 #13
On Jul 8, 4:03 am, CBFalconer <cbfalco...@yahoo.comwrote:
Guru Jois wrote:

... snip ...
Is size_t and all such stuffs portable in c? If not what to make
it so?

Yes. That is, in part, why this newsgroup limits the topic to
STANDARD C, and considers references to system dependent things as
being off-topic. Read the standard.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account fromhttp://www.teranews.com
How and where can I read to understand the perfect knowledge about C
standards.
Any docs/links to learn pure portable programs for C??? Docs
prefered..

Guru Jois

Jul 9 '07 #14
Guru Jois wrote:
On Jul 8, 4:03 am, CBFalconer <cbfalco...@yahoo.comwrote:
Guru Jois wrote:

... snip ...
Is size_t and all such stuffs portable in c? If not what to make
it so?
Yes. That is, in part, why this newsgroup limits the topic to
STANDARD C, and considers references to system dependent things as
being off-topic. Read the standard.

How and where can I read to understand the perfect knowledge about C
standards.
Any docs/links to learn pure portable programs for C??? Docs
prefered..
As far as online tutorials are concerned I'll recommend Steve Summit's
one:

<http://www.eskimo.com/~scs/cclass/>

Also he maintains the very useful C FAQ:

<http://www.c-faq.com/>

There's also a clc "wiki":

<http://clc-wiki.net/>

Other resources include:

<http://www.lysator.liu.se/c/>
<http://www.dinkumware.com/manuals/>
<http://www-ccs.ucsd.edu/c/>
<http://www.open-std.org/jtc1/sc22/wg14/ - Site for the draft
Standard.
<http://www.knosof.co.uk/cbook/cbook.html>
<http://www.cpax.org.uk/prg/portable/c/index.php>

Jul 9 '07 #15
santosh said:

<snip>
As far as online tutorials are concerned I'll recommend Steve Summit's
one:

<http://www.eskimo.com/~scs/cclass/>
Please allow me to add the Tom Torfs tutorial URL:

<http://cprog.tomsweb.net/cintro.html>

Tom used to be a regular (and highly respected) comp.lang.c contributor.
Then, one day, he asked a question about C99, and it transpired that he
was writing a C99 preprocessor. He has not been seen since.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 9 '07 #16
On Sun, 08 Jul 2007 02:36:55 -0700, santosh wrote:
>Guru Jois wrote:
>On Jul 5, 6:42 pm, Peter Nilsson <a...@acay.com.auwrote:
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
empriser wrote:
...
Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer,
after last call fread as if return 0.

fread returns the number of elements that were
read and stored in the buffer. If fread returns 10,
it successfully read and stored 10 elements. If
fread returns 0, it read and stored ... <wait for
it... no elements.

In other words, code as...

static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);

...rather than...

static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);

Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.

Is size_t and all such stuffs portable in c? If not what to make it
so?

size_t is defined in the Standard, so it's certainly portable. New
users to C tend to have some confusion over using size_t objects with
printf and family. Generally using the lu format specifier with a cast
to the appropriate type is recommended. If you can, and want to, use
C99's additions the zu specifier is specifically there for size_t.
size_t is not portable because you all don't know the size it has
only uint8_t uint16_t uint32_t, uint64_t are portable
Jul 9 '07 #17
Ča\/b said:
On Sun, 08 Jul 2007 02:36:55 -0700, santosh wrote:
<snip>
>>size_t is defined in the Standard, so it's certainly portable. New
users to C tend to have some confusion over using size_t objects with
printf and family. Generally using the lu format specifier with a cast
to the appropriate type is recommended. If you can, and want to, use
C99's additions the zu specifier is specifically there for size_t.

size_t is not portable because you all don't know the size it has
Nonsense. It is exactly sizeof(size_t) bytes in size.
only uint8_t uint16_t uint32_t, uint64_t are portable
My implementation has never heard of them, and gives me compilation
errors when I try to use them. So much for "portable".

But my implementation understands size_t just fine, thanks.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 9 '07 #18
Ča\/b wrote, On 09/07/07 07:42:
On Sun, 08 Jul 2007 02:36:55 -0700, santosh wrote:
>Guru Jois wrote:
>>On Jul 5, 6:42 pm, Peter Nilsson <a...@acay.com.auwrote:
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
empriser wrote:
>...
>Yes my buffer size is n (n 1).
>How do I know there are how many bytes in buffer,
>after last call fread as if return 0.
fread returns the number of elements that were
read and stored in the buffer. If fread returns 10,
it successfully read and stored 10 elements. If
fread returns 0, it read and stored ... <wait for
it... no elements.
In other words, code as...

static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);

...rather than...

static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);

Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.
Is size_t and all such stuffs portable in c? If not what to make it
so?
size_t is defined in the Standard, so it's certainly portable. New
users to C tend to have some confusion over using size_t objects with
printf and family. Generally using the lu format specifier with a cast
to the appropriate type is recommended. If you can, and want to, use
C99's additions the zu specifier is specifically there for size_t.

size_t is not portable because you all don't know the size it has
only uint8_t uint16_t uint32_t, uint64_t are portable
Rubbish. There is no guarantee that the types you are suggesting are
available (even assuming C99) so they are less portable than size_t
which is *guaranteed* to exist. size_t is also the type returned by
fread (the function being called above), so whatever it is a variable of
type size_t is *guaranteed* to be large enough.
--
Flash Gordon
Jul 9 '07 #19
On Mon, 09 Jul 2007 08:19:40 +0100, Flash Gordon
<sp**@flash-gordon.me.ukwrote:
>Ča\/b wrote, On 09/07/07 07:42:
>On Sun, 08 Jul 2007 02:36:55 -0700, santosh wrote:
>>Guru Jois wrote:
On Jul 5, 6:42 pm, Peter Nilsson <a...@acay.com.auwrote:
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
>empriser wrote:
>>...
>>Yes my buffer size is n (n 1).
>>How do I know there are how many bytes in buffer,
>>after last call fread as if return 0.
> fread returns the number of elements that were
>read and stored in the buffer. If fread returns 10,
>it successfully read and stored 10 elements. If
>fread returns 0, it read and stored ... <wait for
>it... no elements.
In other words, code as...
>
static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);
>
...rather than...
>
static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);
>
Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.
Is size_t and all such stuffs portable in c? If not what to make it
so?
size_t is defined in the Standard, so it's certainly portable. New
users to C tend to have some confusion over using size_t objects with
printf and family. Generally using the lu format specifier with a cast
to the appropriate type is recommended. If you can, and want to, use
C99's additions the zu specifier is specifically there for size_t.

size_t is not portable because you all don't know the size it has
only uint8_t uint16_t uint32_t, uint64_t are portable

Rubbish. There is no guarantee that the types you are suggesting are
available (even assuming C99) so they are less portable than size_t
which is *guaranteed* to exist. size_t is also the type returned by
fread (the function being called above), so whatever it is a variable of
type size_t is *guaranteed* to be large enough.
each data definition that not fixed the size is unportable
each operation to data operand not well definited is unportable
Jul 9 '07 #20
Ča\/b said:

<snip>
each data definition that not fixed the size is unportable
Why?
each operation to data operand not well definited is unportable
size_t is well-defined.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 9 '07 #21
Ča/b wrote:
On Mon, 09 Jul 2007 08:19:40 +0100, Flash Gordon
<sp**@flash-gordon.me.ukwrote:
Ča\/b wrote, On 09/07/07 07:42:
<snip>
size_t is not portable because you all don't know the size it has
only uint8_t uint16_t uint32_t, uint64_t are portable
Rubbish. There is no guarantee that the types you are suggesting are
available (even assuming C99) so they are less portable than size_t
which is *guaranteed* to exist. size_t is also the type returned by
fread (the function being called above), so whatever it is a variable of
type size_t is *guaranteed* to be large enough.

each data definition that not fixed the size is unportable
How come then dynamically typed programming languages like Python and
Common Lisp are so portable and popular?
each operation to data operand not well definited is unportable
That's certainly true, but that's irrelevant to our discussion, since
size_t is well defined by the C Standard. What problems do you
specifically face when you use size_t?

Jul 9 '07 #22
On Mon, 09 Jul 2007 08:31:03 +0000, Richard Heathfield wrote:
>Ča\/b said:
>each data definition that not fixed the size is unportable

Why?
easy
>each operation to data operand not well definited is unportable

size_t is well-defined.
portable in my country means: i write a X language program;
that program run the same way in all machines
in the world that have a X language conform compiler

then you can argue how this program is portable
in the standard C language

#include <stdio.h>
#include <stdlib.h>

int main(void)
{size_t z=0x2FFFF, h=0xFFFFFFFF;
z=z*z;
printf("Bits(size_t) 32 ?\n");

if(h<=0xFFFF||z<=h)
printf("No\n" );
else printf("Yes\n");

return 0;
}

because in each machine it could answer in a different way.
So what do you mean for the word "portable"? it is a meaningless word

in each machine where there are definitions like "size_t=number"
or where there are operations with size_t type variable =they are
not portable by definition (in each machine could be a different
result)

the problem is: size_t has different size each machine
but let it be size_t has 64 bits for all machine in the world
(or it is an memory only dipendent data type like a bignumber)

the problem could be for "*" function: can "*" function is the same in
all the machine and have the same result for the same operands?

the same for all other operators
the same for all UB and machine dipendent results
the same for all other "fixed all different size" data types
Jul 9 '07 #23
Ča\/b said:

<snip>
portable in my country means: i write a X language program;
that program run the same way in all machines
in the world that have a X language conform compiler

then you can argue how this program is portable
in the standard C language

#include <stdio.h>
#include <stdlib.h>

int main(void)
{size_t z=0x2FFFF, h=0xFFFFFFFF;
No, this isn't portable, because C doesn't guarantee size_t can store
values as high as 0x2FFFF.

The fact that you can write a non-portable program using size_t does not
mean size_t is not portable.
So what do you mean for the word "portable"?
I mean that the program will achieve the same computational objective,
regardless of the implementation used to translate it.
it is a meaningless word
To you, maybe, but not to me.
in each machine where there are definitions like "size_t=number"
or where there are operations with size_t type variable =they are
not portable by definition (in each machine could be a different
result)
Two levers can be of different lengths, yet both can provide leverage,
and you can use either to shift a rock. Just as the concept of
"leverage" is portable across levers, so the concept of object size is
portable across implementations - and size_t is the type with which we
measure object sizes.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 9 '07 #24
In article <31********************************@4ax.com>, Ča\\/b <al@f.gwrote:
>portable in my country means: i write a X language program;
that program run the same way in all machines
in the world that have a X language conform compiler
>then you can argue how this program is portable
in the standard C language
[...]
>because in each machine it could answer in a different way.
"running the same way" does not mean the same as "will
produce the same answer". For example, a program to print
out the current calendar time might have the same code
on all the systems, but it is going to produce a different
answer when run on each one of them.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Jul 9 '07 #25
Ča/b wrote:
On Mon, 09 Jul 2007 08:31:03 +0000, Richard Heathfield wrote:

size_t is well-defined.

portable in my country means: i write a X language program;
that program run the same way in all machines
in the world that have a X language conform compiler

then you can argue how this program is portable
in the standard C language

#include <stdio.h>
#include <stdlib.h>

int main(void)
{size_t z=0x2FFFF, h=0xFFFFFFFF;
You can't expect to portably store arbitrarily large values. size_t
can store values in the range of 0 ... SIZE_MAX. What's ill-defined
about this?
z=z*z;
Here you're performing an arithmetic calculation without checking for
the possibility of wrap-around. Again results might vary across
implementations, but this is not exclusive to size_t types.
printf("Bits(size_t) 32 ?\n");

if(h<=0xFFFF||z<=h)
You're comparing objects which might not hold the values intended for
them.
printf("No\n" );
else printf("Yes\n");

return 0;
}

because in each machine it could answer in a different way.
So what do you mean for the word "portable"? it is a meaningless word
And in what way is this exclusive to size_t. This is true for all of
C's numeric types. Each type's size and range are implementation
dependant except that certain minimum values are guaranteed by the
Standard. That's the price you'll have to pay for using an efficient,
statically typed language.

<snip>
the problem is: size_t has different size each machine
but let it be size_t has 64 bits for all machine in the world
(or it is an memory only dipendent data type like a bignumber)
If you want a language with dynamically sized types, there're plenty
of them floating around. C was not defined to be such a language. On
the other hand, if you stick to what's guaranteed by the Standard, you
_can_ achieve a very high level of source code portability. The
problem is, you want guarantees the Standard is not providing.

<snip>

Jul 9 '07 #26
On Mon, 09 Jul 2007 10:19:09 +0200, "Ča\\/b" <al@f.gwrote:
snip
>each data definition that not fixed the size is unportable
each operation to data operand not well definited is unportable
Well then, you must not use int either since there are a plethora of
16-bit and 32-bit implementations. You probably don't use char either
since we know sizeof(char) is 1 but we don't know anything about
CHAR_BIT other than it is at least 8.
Remove del for email
Jul 10 '07 #27
On Jul 8, 11:25 pm, santosh <santosh....@gmail.comwrote:
As far as online tutorials are concerned I'll recommend Steve Summit's
one:

<http://www.eskimo.com/~scs/cclass/>

Also he maintains the very useful C FAQ:

<http://www.c-faq.com/>

There's also a clc "wiki":

<http://clc-wiki.net/>

Other resources include:

<http://www.lysator.liu.se/c/>
<http://www.dinkumware.com/manuals/>
<http://www-ccs.ucsd.edu/c/>
<http://www.open-std.org/jtc1/sc22/wg14/ - Site for the draft
Standard.
<http://www.knosof.co.uk/cbook/cbook.html>
<http://www.cpax.org.uk/prg/portable/c/index.php>
Thanks Santhosh

Jul 10 '07 #28
On Jul 8, 11:41 pm, Richard Heathfield <r...@see.sig.invalidwrote:
santosh said:

<snip>
As far as online tutorials are concerned I'll recommend Steve Summit's
one:
<http://www.eskimo.com/~scs/cclass/>

Please allow me to add the Tom Torfs tutorial URL:

<http://cprog.tomsweb.net/cintro.html>

Tom used to be a regular (and highly respected) comp.lang.c contributor.
Then, one day, he asked a question about C99, and it transpired that he
was writing a C99 preprocessor. He has not been seen since.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Thanks to Richard too.

Jul 10 '07 #29
Richard Heathfield wrote:
Ča\/b said:

<snip>
>each data definition that not fixed the size is unportable

Why?
>each operation to data operand not well definited is unportable

size_t is well-defined.
Hint: Ča\/b is a known troll.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jul 11 '07 #30
Guru Jois wrote:
CBFalconer <cbfalco...@yahoo.comwrote:
>Guru Jois wrote:

... snip ...
>>Is size_t and all such stuffs portable in c? If not what to make
it so?

Yes. That is, in part, why this newsgroup limits the topic to
STANDARD C, and considers references to system dependent things as
being off-topic. Read the standard.

How and where can I read to understand the perfect knowledge about
C standards. Any docs/links to learn pure portable programs for
C??? Docs prefered..
Please ensure you snip at least the sigs (the portion following the
"-- " marker). To reply to your query, try the URLs below as a
start.

--
Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html (C-faq)
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/(C99 std)
<http://www.dinkumware.com/refxc.html (C-library}
<http://gcc.gnu.org/onlinedocs/ (GNU docs)
<http://clc-wiki.net/wiki/C_community:comp.lang.c:Introduction>

--
Posted via a free Usenet account from http://www.teranews.com

Jul 11 '07 #31

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Brady | last post: by
2 posts views Thread by Luc Holland | last post: by
4 posts views Thread by janssenssimon | last post: by
2 posts views Thread by Richard Hsu | last post: by
8 posts views Thread by M. ┼hman | last post: by
5 posts views Thread by loudking | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.