469,917 Members | 1,783 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Offline Tutorial

I am attempting to learn C on a computer that does not have internet
access. Can anyone find a C tutorial that can be completely
downloaded? I wish to transfer it from a computer that can get online
to my computer. (The one that can not get on the internet.) I don't
need an absolute beginner tutorial, as I have used Python before.

Thanks!
- Ian Shearin

May 15 '07 #1
37 7793
On May 15, 4:57 pm, Zabac <Zaba...@gmail.comwrote:
I am attempting to learn C on a computer that does not have internet
access. Can anyone find a C tutorial that can be completely
downloaded? I wish to transfer it from a computer that can get online
to my computer. (The one that can not get on the internet.) I don't
need an absolute beginner tutorial, as I have used Python before.

Thanks!
- Ian Shearin
I'm no C expert, but anyway...

Try and see if this suites your taste:
http://en.wikibooks.org/wiki/C_Progr.../Print_version

Plus, if you're going with windows, you may want to try Dev CPP:
http://www.bloodshed.net/devcpp.html
I think they have some offline documentation as well as some CD image,
but I haven't tried them.

May 15 '07 #2
>>>>"Z" == Zabac <Za*****@gmail.comwrites:

ZI am attempting to learn C on a computer that does not have
Zinternet access. Can anyone find a C tutorial that can be
Zcompletely downloaded?

There is a most excellent tutorial called _The C Programming
Language_. You may "download" it from your nearest bookstore; it's in
a strange archival format known as a "book."

Charlton

--
Charlton Wilbur
cw*****@chromatico.net
May 15 '07 #3
Zabac wrote:
I am attempting to learn C on a computer that does not have internet
access. Can anyone find a C tutorial that can be completely
downloaded? I wish to transfer it from a computer that can get online
to my computer. (The one that can not get on the internet.) I don't
need an absolute beginner tutorial, as I have used Python before.

Thanks!
- Ian Shearin
You can download
o A C Tutorial
o A C Compiler
o A development environment

at no cost from

http://www.cs.virginia.edu/~lcc-win32

The tutorial builds from ground up, the compiler is simple and easy
to use. It comes with an IDE with project management, makefile
generation, browse information generation and many other goodies.

Included is also a graphical debugger, and a ressource editor.

http://www.cs.virginia.edu/~lcc-win32
or
http://www.q-software-solutions.de
May 15 '07 #4
Zabac wrote, On 15/05/07 20:57:
I am attempting to learn C on a computer that does not have internet
access. Can anyone find a C tutorial that can be completely
downloaded? I wish to transfer it from a computer that can get online
to my computer. (The one that can not get on the internet.) I don't
need an absolute beginner tutorial, as I have used Python before.
The best recommendation I can give is not available for download, and
that is Kernighan and Ritchie, The C Programming Language, Second
Edition. It has the added advantage of still being a good reference
after years of C programming experience. The comp.lang.c FAQ is also a
good reference.

Be warned that there are a lot of bad and very bad C tutorials on the net.
--
Flash Gordon
May 15 '07 #5
jacob navia wrote, On 15/05/07 21:44:
Zabac wrote:
>I am attempting to learn C on a computer that does not have internet
access. Can anyone find a C tutorial that can be completely
downloaded? I wish to transfer it from a computer that can get online
to my computer. (The one that can not get on the internet.) I don't
need an absolute beginner tutorial, as I have used Python before.
<snip>
You can download
o A C Tutorial
o A C Compiler
o A development environment

at no cost from

http://www.cs.virginia.edu/~lcc-win32
<snip>

Please note that lcc-win32 is Jacob's product. This is not to say that
it is bad, just that his opinion is biased.

Jacob, pointing at your stuff was a reasonable response, but you should
say that it is yours when posting the link.
--
Flash Gordon
May 15 '07 #6
On May 15, 9:44 pm, Flash Gordon <s...@flash-gordon.me.ukwrote:
Zabac wrote, On 15/05/07 20:57:
I am attempting to learn C on a computer that does not have internet
access. Can anyone find a C tutorial that can be completely
downloaded? I wish to transfer it from a computer that can get online
to my computer. (The one that can not get on the internet.) I don't
need an absolute beginner tutorial, as I have used Python before.

The best recommendation I can give is not available for download, and
that is Kernighan and Ritchie, The C Programming Language, Second
Edition.
I think it is (or perhaps was) available as an ebook - certainly I
know a couple of people who've got electronic copies, though I've
never myself managed to find a site selling it for download.
It has the added advantage of still being a good reference
after years of C programming experience. The comp.lang.c FAQ is also a
good reference.

Be warned that there are a lot of bad and very bad C tutorials on the net.
--
Flash Gordon
May 15 '07 #7
Fr************@googlemail.com said:

<snip>
>
I think [K&R2] is (or perhaps was) available as an ebook
No, Prentice Hall have never released it electronically.
- certainly I
know a couple of people who've got electronic copies, though I've
never myself managed to find a site selling it for download.
If ever you do find such a site, or indeed a site offering a free copy,
the proper course is to pen a quick email to Prentice Hall, informing
them of the URL.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
May 15 '07 #8
Flash Gordon wrote:
>
Please note that lcc-win32 is Jacob's product. This is not to say that
it is bad, just that his opinion is biased.

Jacob, pointing at your stuff was a reasonable response, but you should
say that it is yours when posting the link.
Well, I do not like to make me self proclaimed publicity.

In the page I am referring to, my name is written anyway, so it is easy
to see. But writing:

"lcc-win32 is written by me and it is a great thing" looks somehow
awkward...

I listed some features, nothing really flashy... er... sorry Flash

:-)

May 15 '07 #9
Richard Heathfield wrote:
Fr************@googlemail.com said:

<snip>
>>I think [K&R2] is (or perhaps was) available as an ebook


No, Prentice Hall have never released it electronically.

>>- certainly I
know a couple of people who've got electronic copies, though I've
never myself managed to find a site selling it for download.


If ever you do find such a site, or indeed a site offering a free copy,
the proper course is to pen a quick email to Prentice Hall, informing
them of the URL.
There is a growing list of "warez" sites, where any possible book
seems to be there. All of them scanned and available in pdf
format.

This must be an industrial type of operation, made very easy by
current technology. Using an OCR, you can put *any* book on line
now.

It is like music and the mp3. Everything is available for free,
I would bet that if you look for your own book you will be able
to download it from some "warez" site.

In the other hand, it would be a good thing to put for free books
whose copyright has expired, and / or the publisher renounces to his
rights when the book goes out of print.

jacob
May 15 '07 #10
jacob navia said:
Flash Gordon wrote:
>>
Please note that lcc-win32 is Jacob's product. This is not to say
that it is bad, just that his opinion is biased.

Jacob, pointing at your stuff was a reasonable response, but you
should say that it is yours when posting the link.

Well, I do not like to make me self proclaimed publicity.
That doesn't tie in with your previous posting behaviour. But Mr Gordon
isn't asking you to publicise yourself. He's simply asking you to make
it quite clear that the product you are recommending is one in which
you have a vested interest.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
May 15 '07 #11
jacob navia wrote:
In the other hand, it would be a good thing to put for free books
whose copyright has expired, and / or the publisher renounces to his
rights when the book goes out of print.
http://www.gutenberg.org/wiki/Main_Page

- Ernie http://home.comcast.net/~erniew
May 16 '07 #12
On May 15, 11:34 pm, jacob navia <j...@jacob.remcomp.frwrote:
Richard Heathfield wrote:
Francine.Ne...@googlemail.com said:
<snip>
>I think [K&R2] is (or perhaps was) available as an ebook
No, Prentice Hall have never released it electronically.
>- certainly I
know a couple of people who've got electronic copies, though I've
never myself managed to find a site selling it for download.
If ever you do find such a site, or indeed a site offering a free copy,
the proper course is to pen a quick email to Prentice Hall, informing
them of the URL.

There is a growing list of "warez" sites, where any possible book
seems to be there. All of them scanned and available in pdf
format.

This must be an industrial type of operation, made very easy by
current technology. Using an OCR, you can put *any* book on line
now.

It is like music and the mp3. Everything is available for free,
I would bet that if you look for your own book you will be able
to download it from some "warez" site.
Well, I personally think it's a good thing to buy a book and put
royalties in the pocket of the person who's invested the time to write
it, instead of scrounging it illegally. The tone of your discussion of
"warez" sites seems at best neutral, and in some ways makes them seem
quite positive - I don't think that's the sort of thing you should be
encouraging.
In the other hand, it would be a good thing to put for free books
whose copyright has expired, and / or the publisher renounces to his
rights when the book goes out of print.

jacob

May 16 '07 #13
Fr************@googlemail.com wrote:
Well, I personally think it's a good thing to buy a book and put
royalties in the pocket of the person who's invested the time to write
it, instead of scrounging it illegally. The tone of your discussion of
"warez" sites seems at best neutral, and in some ways makes them seem
quite positive - I don't think that's the sort of thing you should be
encouraging.
No way.

I have never said anything like that, and if you understand that from
my message you are completely wrong. I do not accept stealing people
from their rights and copyright is necessary to keep people writing.

Artists, writers, and creatives in general should be compensated
for their efforts by the public that profits from their works.

True, I used a neutral tone, because it is not my style to get upset
and distribute insults around. That could be misunderstood as
approval, and if that is the case I would like to clarify that.

jacob
May 16 '07 #14
Zabac wrote:
I am attempting to learn C on a computer that does not have internet
access. Can anyone find a C tutorial that can be completely
downloaded? I wish to transfer it from a computer that can get online
to my computer. (The one that can not get on the internet.) I don't
need an absolute beginner tutorial, as I have used Python before.

Thanks!
- Ian Shearin
A pdf tutorial on C. It is in draft though

http://www.beej.us/guide/

I wrote my first socket code using Beej's guide to network programming. I
found it really funny and interesting. I hope C guide stands up to the
quality set by network programming guide.

Thanks,
Tejas

Disclaimer: I haven't read this C guide yet.
May 17 '07 #15
Thanks for your input, everyone! Dev-Cpp it a great compiler and your
tutorial suggestions have been helpful. By the way, I am planning to
buy a book once I get into C more.

- Ian Shearin

May 17 '07 #16
jacob navia wrote:
>
.... snip ...
>
This must be an industrial type of operation, made very easy by
current technology. Using an OCR, you can put *any* book on line
now.
.... snip ...
>
In the other hand, it would be a good thing to put for free books
whose copyright has expired, and / or the publisher renounces to
his rights when the book goes out of print.
The simplest thing would be to alter the laws, so that anything
that is not available for, say, 5 years, becomes public property.
This is short enough to release valuable software, but long enough
to allow the owners to maintain copyright easily.

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

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

May 17 '07 #17
Tejas Kokje wrote, On 17/05/07 03:27:
Zabac wrote:
>I am attempting to learn C on a computer that does not have internet
access. Can anyone find a C tutorial that can be completely
downloaded? I wish to transfer it from a computer that can get online
to my computer. (The one that can not get on the internet.) I don't
need an absolute beginner tutorial, as I have used Python before.

Thanks!
- Ian Shearin

A pdf tutorial on C. It is in draft though

http://www.beej.us/guide/

I wrote my first socket code using Beej's guide to network programming. I
found it really funny and interesting. I hope C guide stands up to the
quality set by network programming guide.

Thanks,
Tejas

Disclaimer: I haven't read this C guide yet.
Well, it passes my first test. To quote from it:
| ... For instance, here is the usage of gets():
|
| Don't use gets().

With this tutorial the OP needs to be aware that // style comments are a
syntax error in C89, the most commonly implemented standard, although
they are valid in C99. Also, the tutorial uses implicit int which is bad
style and no longer valid in C99. Also the tutorial consistently fails
to return a value from main which is bad. scanf is used without checking
the value it returns to see if it succeeded. It is also messed up when
it comes to arrays, specifically claiming the following are equivalent
which is wrong:
| init_array(my_data, 10); /* note lack of [] notation */
| init_array(&my_data, 10); /* note lack of [] notation */

Having given some criticism (I've not listed all the problems), please
be aware that this is far less than I can usually find wrong with a
quick scan.
--
Flash Gordon
May 17 '07 #18
On Wed, 16 May 2007 19:27:58 -0700, Tejas Kokje
<bi*************@gmail.comwrote:
>Zabac wrote:
>I am attempting to learn C on a computer that does not have internet
access. Can anyone find a C tutorial that can be completely
downloaded? I wish to transfer it from a computer that can get online
to my computer. (The one that can not get on the internet.) I don't
need an absolute beginner tutorial, as I have used Python before.

Thanks!
- Ian Shearin

A pdf tutorial on C. It is in draft though

http://www.beej.us/guide/

I wrote my first socket code using Beej's guide to network programming. I
found it really funny and interesting. I hope C guide stands up to the
quality set by network programming guide.

Thanks,
Tejas

Disclaimer: I haven't read this C guide yet.
On page 1 he says you can use a C++ compiler to compile C code.

On page 6 he defines main with "main(){"

On page 10, he demonstrates a lack of understanding between a
declaration and a definition..

And then he talks about variables on the stack and the heap.

It's kind of a shame because I think he has a good presentation style.
Unfortunately, the novice the text is aimed at will not be able to
distinguish the ignorable from the relevant.
Remove del for email
May 17 '07 #19
Barry Schwarz <sc******@doezl.netwrote:
>On page 1 he says you can use a C++ compiler to compile C code.
[snip]
*blush* I was kinda hoping no one would see it until two weeks from
now, but it has been online for years.

Well, let me tell you the good news: I already knew about all the things
you listed.

Now let me tell you the bad news: there are many many more errors I
already know about that you didn't list. The thing is 125 pages long of
un-proofred text--if there were only 10 errors, it would be a freakin'
miracle. Some is just lame typo crap, and some is stuff I didn't know.

Part of the reason I came back to CLC was to get my shit together to get
this stuff right.

Now, stay tuned because I've finally finished the processor that renders
the guides, so I'm porting the C guide to it. (First I had to take the
IPC guide I wrote literally 10 years ago and upgrade it. I shudder to
think of what it's like. I did fix the most horrible semaphore error.)

Everything you list will be (more) fixed as I work on it on the plane
and train during my upcoming vacation... You can email me if you want,
because I'm likely to miss stuff in this thread for not reading news for
the next week.

(And then, because I'm not pleased with the overall structure of the
thing, it will be overhauled and a new set of crazy errors will be
introduced, but hopefully more of the typo variety, and less of the
basic misunderstanding variety.)

So I'm more than willing to listen to advice and make fixes, especially
now that the C guide has reached the front-burner, but if anyone is
personally offended by my putting these online while still error-ridden,
I don't give a shit. If you don't like it, go buy Heathfield's book.

Cheers,
-Beej--running off to catch a plane (with copies of these messages)

PS. Thank you Mr. Gordon for pointing out the thread to me!

May 17 '07 #20
In article <f2**********@news.albasani.net>,
Beej Jorgensen <be**@beej.uswrote:
>So I'm more than willing to listen to advice and make fixes, especially
now that the C guide has reached the front-burner,
Well, if you're looking for advice on fixes to make, you came to the
right place.
but if anyone is
personally offended by my putting these online while still error-ridden,
I don't give a shit. If you don't like it, go buy Heathfield's book.
Most of us are pretty hard to offend; it's just that our fanatical
devotion to accuracy shines through when we encounter things like this.
As long as we know (and know that you know) that they're works-in-progress
and that the errors we find and point out will be corrected, that puts
you way ahead of most tutorial writers.
dave
(maybe I should go check it out too...)

--
Dave Vandervies dj******@csclub.uwaterloo.ca
Actually, anything false posted here tends to get corrected pretty quickly.
Actually, anything posted here tends to get corrected pretty quickly.
--Ben Pfaff and Joe Wright in comp.lang.c
May 17 '07 #21
On May 17, 5:09 am, Barry Schwarz <schwa...@doezl.netwrote:
On Wed, 16 May 2007 19:27:58 -0700, Tejas Kokje

<binarysemaph...@gmail.comwrote:
Zabac wrote:
I am attempting to learn C on a computer that does not have internet
access. Can anyone find a C tutorial that can be completely
downloaded? I wish to transfer it from a computer that can get online
to my computer. (The one that can not get on the internet.) I don't
need an absolute beginner tutorial, as I have used Python before.
Thanks!
- Ian Shearin
A pdf tutorial on C. It is in draft though
http://www.beej.us/guide/
I wrote my first socket code using Beej's guide to network programming. I
found it really funny and interesting. I hope C guide stands up to the
quality set by network programming guide.
Thanks,
Tejas
Disclaimer: I haven't read this C guide yet.

On page 1 he says you can use a C++ compiler to compile C code.

On page 6 he defines main with "main(){"

On page 10, he demonstrates a lack of understanding between a
declaration and a definition..

And then he talks about variables on the stack and the heap.

It's kind of a shame because I think he has a good presentation style.
Unfortunately, the novice the text is aimed at will not be able to
distinguish the ignorable from the relevant.

Remove del for email
Thanks. As I said, I haven't read the guide. I hoped it would be as
good as network programming guide. But obviously there are some flaws.
I have cc'd original author. Also, on your first comment, what is
wrong in compiling C code with C++ compiler ??

Tejas Kokje


May 17 '07 #22
On Thu, 17 May 2007 14:54:57 +0000 (UTC), Beej Jorgensen
<be**@beej.uswrote:
>Part of the reason I came back to CLC was to get my shit together to get
this stuff right.
The right place, for sure :-)

I like your writing style, and your attitude. Don't forget to come
back.

--
Al Balmer
Sun City, AZ
May 17 '07 #23
Tejas Kokje wrote, On 17/05/07 19:37:

<snip>
I have cc'd original author. Also, on your first comment, what is
wrong in compiling C code with C++ compiler ??
The same thing that is wrong with compiling C++ code with a C compiler.
C++ and C are not the same.
--
Flash Gordon
May 17 '07 #24
Tejas Kokje said:
[...] what is wrong in compiling C code with C++ compiler ??
What is wrong with compiling C code with a Pascal compiler?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
May 17 '07 #25
On May 17, 12:09 pm, Flash Gordon <s...@flash-gordon.me.ukwrote:
Tejas Kokje wrote, On 17/05/07 19:37:

<snip>
I have cc'd original author. Also, on your first comment, what is
wrong in compiling C code with C++ compiler ??

The same thing that is wrong with compiling C++ code with a C compiler.
C++ and C are not the same.
--
Flash Gordon
Ok.that may be for C89 or K & R C. But can somebody show me a C99
program which won't compile under C++ compiler ? I am just curious.

Tejas Kokje

May 17 '07 #26
Tejas Kokje wrote:
>
Ok.that may be for C89 or K & R C. But can somebody show me a C99
program which won't compile under C++ compiler ? I am just curious.
#include <stdlib.h>

int main()
{
char* p = malloc(1);
}

--
Ian Collins.
May 17 '07 #27
On May 17, 2:56 pm, Ian Collins <ian-n...@hotmail.comwrote:
Tejas Kokje wrote:
Ok.that may be for C89 or K & R C. But can somebody show me a C99
program which won't compile under C++ compiler ? I am just curious.

#include <stdlib.h>

int main()
{
char* p = malloc(1);

}

--
Ian Collins.
Got it. Thanks Ian.

May 17 '07 #28
In article <11**********************@w5g2000hsg.googlegroups. com>,
Tejas Kokje <bi*************@gmail.comwrote:
>Ok.that may be for C89 or K & R C. But can somebody show me a C99
program which won't compile under C++ compiler ? I am just curious.
int main(void)
{
char *namespace = "http://example.org";
return 0;
}

"namespace" is a keyword in C++.

I have written C code which turned out to have this problem, and
"namespace" was used as a struct tag in a header, which made
it impossible to link with C++. The code was already in use, so
I didn't want to change the name. I ended up doing this:

#ifdef __cplusplus
/* unfortunately the word "namespace" is reserved in C++ */
#define RXP_NAMESPACE name_space
#else
#define RXP_NAMESPACE namespace
#endif

and referring to RXP_NAMESPACE throughout the header.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
May 17 '07 #29
Ian Collins wrote, On 17/05/07 22:56:
Tejas Kokje wrote:
>Ok.that may be for C89 or K & R C. But can somebody show me a C99
program which won't compile under C++ compiler ? I am just curious.
#include <stdlib.h>

int main()
{
char* p = malloc(1);
}
Or an even shorter compilation unit (not a complete program):

int new;
--
Flash Gordon
May 17 '07 #30
In article <fk************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:
>Tejas Kokje wrote:
>>Ok.that may be for C89 or K & R C. But can somebody show me a C99
program which won't compile under C++ compiler ? I am just curious.
>Or an even shorter compilation unit (not a complete program):

int new;
Fleshing out your example to a distilled version of a real-life case:
--------
struct something *match_old_with_new(struct list *old,struct list *new)
{
/*do something here*/
}
--------
That one caused no end of fun when some twit decided to completely
gratuitiously introduce C++ code into that translation unit.
(No, your single global class instance is not more efficient, easier to
understand, more maintainable, or in any other way better than my small
collection of static variables.)
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
Ah, thanks. I've got plenty of flames for being too pedantic. It is
refreshing to be told I'm not pedantic enough.
--Joona I Palaste in comp.lang.c
May 18 '07 #31
dj******@caffeine.csclub.uwaterloo.ca (Dave Vandervies) writes:
In article <fk************@news.flash-gordon.me.uk>,
Flash Gordon <sp**@flash-gordon.me.ukwrote:
>>Tejas Kokje wrote:
Ok.that may be for C89 or K & R C. But can somebody show me a C99
program which won't compile under C++ compiler ? I am just curious.
>>Or an even shorter compilation unit (not a complete program):

int new;

Fleshing out your example to a distilled version of a real-life case:
--------
struct something *match_old_with_new(struct list *old,struct list *new)
{
/*do something here*/
}
--------
That one caused no end of fun when some twit decided to completely
gratuitiously introduce C++ code into that translation unit.
(No, your single global class instance is not more efficient, easier to
understand, more maintainable, or in any other way better than my small
collection of static variables.)
Or than a single global struct object, which would be equivalent to a
C++ class instance *and* perfectly valid C.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 18 '07 #32
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>dj******@caffeine.csclub.uwaterloo.ca (Dave Vandervies) writes:
>(No, your single global class instance is not more efficient, easier to
understand, more maintainable, or in any other way better than my small
collection of static variables.)

Or than a single global struct object, which would be equivalent to a
C++ class instance *and* perfectly valid C.
No, because you see, a C++ class instance lets you bundle the code WITH
the variables, which is Obviously Superior to having to write them below
the variable declarations.
dave
(no, I don't see that as an advantage either)

--
Dave Vandervies dj******@csclub.uwaterloo.ca
And if all else fails, I suppose you could drop your safety diver on
the refreezing ice.
--Anthony de Boer in the scary devil monastery
May 18 '07 #33
dj******@caffeine.csclub.uwaterloo.ca (Dave Vandervies) writes:
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>>dj******@caffeine.csclub.uwaterloo.ca (Dave Vandervies) writes:
>>(No, your single global class instance is not more efficient, easier to
understand, more maintainable, or in any other way better than my small
collection of static variables.)

Or than a single global struct object, which would be equivalent to a
C++ class instance *and* perfectly valid C.

No, because you see, a C++ class instance lets you bundle the code WITH
the variables, which is Obviously Superior to having to write them below
the variable declarations.
Sure, but a C++ class doesn't *have* to include methods; it can be
exactly like a plain C-style struct. I assumed that was what Dave was
talking about.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 18 '07 #34
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>dj******@caffeine.csclub.uwaterloo.ca (Dave Vandervies) writes:
>In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>>>dj******@caffeine.csclub.uwaterloo.ca (Dave Vandervies) writes:
(No, your single global class instance is not more efficient, easier to
understand, more maintainable, or in any other way better than my small
collection of static variables.)

Or than a single global struct object, which would be equivalent to a
C++ class instance *and* perfectly valid C.

No, because you see, a C++ class instance lets you bundle the code WITH
the variables, which is Obviously Superior to having to write them below
the variable declarations.

Sure, but a C++ class doesn't *have* to include methods; it can be
exactly like a plain C-style struct. I assumed that was what Dave was
talking about.
Nope. The C code originally looked like this:
--------
static int available[100];
static int used[100];
static int n_avail,n_used;

void init_id(void) {/*...*/}
int next_id(void) {/*...*/}
void release_id(int) {/*...*/}
--------
When the upper bound (initially fixed at 100) became variable up to a
maximum of 65535, it was replaced with a C++ class that looked like this:
--------
//Manages global state, so only one instance is ever created
class id_manager
{
std::vector<boolis_available;
int max;
int next_to_try;
public:
manager(): is_available(MAX_UPPER_BOUND) {}
void set_max(int new_max);
int get_next(void);
void release(int);
};
--------

Had the code been written from the ground up in C++, it would have ended
up looking quite similar (which is why I didn't use C++ originally;
it didn't offer anything relevant to the problem that C didn't, and I
prefer to work with a smaller language when the bigger one doesn't offer
anything useful), and using a std::vector<boolin the new code would have
been The Right Thing whether or not wrapping it in a class was useful.
But the amount of work taken to transform the entire translation unit
from reasonably well-written C into rather poor C++ would have been
better spent on writing a few dozen lines of code to implement a bitmap
in C (which was a much better way to keep the available-or-not status
of 65535 values than the array of values that worked well for smaller
numbers and had some minor advantages in handling of re-use).
(Actually, the bounds on values used here were properties of external
interfaces, so The Right Solution would have been to fan-out the data to
the external interface handlers, and then manage the ID values separately
for each interface, rather than restrict the system to only interfacing
with one at a time; but that would have required more changes to more
parts of the system than we had time to design, build, and test, and
since we've never deployed a system that talks to more than one of those
external interfaces at a time it wasn't needed.)
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
If you wish to send gifts, just provide me with your banking information,
and I'll select something suitable.
--Eric Schwartz in the scary devil monastery
May 18 '07 #35
Beej Jorgensen wrote:
Barry Schwarz <sc******@doezl.netwrote:
>On page 1 he says you can use a C++ compiler to compile C code.
[snip]

*blush* I was kinda hoping no one would see it until two weeks from
now, but it has been online for years.

Well, let me tell you the good news: I already knew about all the things
you listed.

Now let me tell you the bad news: there are many many more errors I
already know about that you didn't list. The thing is 125 pages long of
un-proofred text--if there were only 10 errors, it would be a freakin'
miracle. Some is just lame typo crap, and some is stuff I didn't know.

Part of the reason I came back to CLC was to get my shit together to get
this stuff right.

Now, stay tuned because I've finally finished the processor that renders
the guides, so I'm porting the C guide to it. (First I had to take the
IPC guide I wrote literally 10 years ago and upgrade it. I shudder to
think of what it's like. I did fix the most horrible semaphore error.)

Everything you list will be (more) fixed as I work on it on the plane
and train during my upcoming vacation... You can email me if you want,
because I'm likely to miss stuff in this thread for not reading news for
the next week.
Fair enough. Sounds as if you might get to a usable tutorial.

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

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

May 20 '07 #36
Tejas Kokje wrote:
>
.... snip ...
>
Thanks. As I said, I haven't read the guide. I hoped it would be
as good as network programming guide. But obviously there are
some flaws. I have cc'd original author. Also, on your first
comment, what is wrong in compiling C code with C++ compiler ??
The languages are different. Do you want to compile Pascal with a
Fortran compiler?

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

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

May 21 '07 #37
On Sun, 20 May 2007, CBFalconer wrote:
Tejas Kokje wrote:
>>
... snip ...
>>
Thanks. As I said, I haven't read the guide. I hoped it would be
as good as network programming guide. But obviously there are
some flaws. I have cc'd original author. Also, on your first
comment, what is wrong in compiling C code with C++ compiler ??

The languages are different. Do you want to compile Pascal with a
Fortran compiler?
Yes. Enclosed please find Maarten Litmaath's Pascal
program (posted on rec.puzzles in 1991):

(* /*
C /) 2/dev/null & echo hello world!; exit
C << 'CC'
C
C This file is a portable:
C - (ANSI/KR) C source, about which lint(1) does not complain/warn;
C - (ISO) Pascal source;
C - (ANSI) Fortran-77 source;
C - (POSIX/V7/BSD/System V) shell script.
C
C*/ foo()) { extern *bar; return ++bar; /*
C*) program {*/} int (* /*
C*) (output); begin writeln('hello world!') end. {
print *, 'hello world!'
end
C*/ bar); main() { puts("hello world!"); return !foo(); /*
CC
C*/}
Tak-Shing
May 21 '07 #38

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by moko | last post: by
3 posts views Thread by Robert Scheer | last post: by
2 posts views Thread by John | last post: by
2 posts views Thread by John | last post: by
10 posts views Thread by Michael Hoffmann | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.