Hello All,
I've been compiling a series of pages about the bad functions and
mistakes that occur in C into a book, subsequently, I now have a moderate
little book of about 32 pages available for download as a PDF file at http://www.pldaniels.com/c-of-peril
It's currently still being worked on and I'm always seeking out new
examples of C being used poorly or broken standard functions.
Regards.
--
PLDaniels - Software - Xamime
Unix systems Internet Development A.B.N. 19 500 721 806
PGP Public Key at http://www.pldaniels.com/gpg-keys.pld
Nov 14 '05
56 2607
Up spake Paul L Daniels: Incidentally, that introductory paragraph shows about the quality of English writing we can expect from the whole book --- not so hot. Never claimed it to yet be an exercise in English literature.
That is not a valid excuse for spelling or grammar mistakes, or
ambiguous or poor wording.
The book is incomplete and will go through an editing phase by 3rd parties.
....but this is. While couched a little over-aggressively, the OP's
criticism is valid, and a significant portion of the prose needs to be
rewritten for clarity.
--
-trent
Math is for kids who can't get by on looks and trench coats alone.
Paul L Daniels wrote: Hello All,
I've been compiling a series of pages about the bad functions and mistakes that occur in C into a book, subsequently, I now have a moderate little book of about 32 pages available for download as a PDF file at
http://www.pldaniels.com/c-of-peril
It's currently still being worked on and I'm always seeking out new examples of C being used poorly or broken standard functions.
Regards.
This examples aren't strictly new...
Many solutions have been proposed, and it wouldn't hurt if you would
review the literature and tell the reader what has been done to addres
this problems.
The string handling of C, designed more than 3 decades ago, is obviously
a very weak feature of the language, as we have discussed repeatedly
here. Microsoft, (to name one) has proposed a safer string library, and
many other people have proposed others.
The same for the eternal free/realloc/malloc problems. I have been
arguing here for a GC based solution, and there is a lot of other
solutions too.
If you want to contribute something more interesting than an old rehash
of previous discussions, a review of the literature is necessary.
jacob
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote #define foo(x) do { bar(x); baz(x); } while(0)
Anyone know if there's a way to do this without relying on
do/while/if/for (etc)?
Nope. But why does it matter? 'do' is just as much a part of the language as the left parenthesis, and it always has been.
It's a minor irritation.
By itself it doesn't matter much, but the cumulative effect of many minor
irritations is that code becomes hard to read, and thus more expensive to
maintain.
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> writes:
[...] 2.3: C++ programmers will not like that you use a struct with the same name as a function.
In a document about C, there's not much reason to care whether C++
programmers will like it or not. On the other hand, C programmers may
dislike it because it's confusing, even if it's perfectly legal. 2.4: Why 'CP_strncpy' but 'zstrncat'? Is there a method to your naming convention? Several of your single-line comments spill over and become syntax errors; this is exactly why Real Programmers[tm] do not use C++-style comments.
The best reason to avoid C++-style comments is that they're not (yet)
portable. C++ and C99 support them; C90 does not, though many pre-C99
compilers do support them as an extension.
"//" comments can be a problem in Usenet postings because there are
points between writing the code and reading it where long lines can be
quietly folded by client software that assumes it's dealing with
paragraphs rather than source code. (The same thing can happen with
string literals and macro definitions, but it's the comments that
people complain about.) This shouldn't be an issue in a document like
a PDF file where you (theoretically) control the formatting yourself.
<OT>
Some languages, such as Perl and Ada, only support comments introduced
by a delimiter and terminated by the end of a line. Personally, I
like that better than C's "/* ... */" comments. If "//" comments were
portable in C, I'd probably use them in preference to "/* ... */"
comments. YMMV.
</OT>
[...]
Listing 3.3 is labeled "Example of segmentation faulting using free," but it does not exhibit a segfault --- it's perfectly valid. Remove the '= NULL' initializer and you've got a case.
But even then, a segfault (whatever that is; C doesn't define the
term) is only one possible consequence of undefined behavior.
[...]
6: "programmin g ... is not the place to express creativity ..." Obviously you have never programmed!
But there is a valid point there. Certain forms of "creativity " are
inappropriate. (I'd expound further if I had time.)
And "obsfuscate d" is misspelled.
--
Keith Thompson (The_Other_Keit h) 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.
I'm sorry, but I think you need to do a great deal of proofreading and
correct your spelling, grammar and style. I gather from the number of
errors in the English that it is probably not your first language. Perhaps
you should have somebody who speaks English proofread and correct the
document for you.
Malcolm wrote: "Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote #define foo(x) do { bar(x); baz(x); } while(0)
Anyone know if there's a way to do this without relying on do/while/if/for (etc)?
Nope. But why does it matter? 'do' is just as much a part of the language as the left parenthesis, and it always has been.
It's a minor irritation. By itself it doesn't matter much, but the cumulative effect of many minor irritations is that code becomes hard to read, and thus more expensive to maintain.
Not at all. The purpose of using it is exactly the opposite - to
allow the macro to be used in normal C contexts without creating
obscure syntax errors in the final code, or requiring special
considerations such as adding or omitting semicolons.
As far as reading the original macro definition is concerned, this
is a well known method, and should not cause any concern
whatsoever.
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
On Sun, 5 Dec 2004, Keith Thompson wrote: "Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> writes: 2.3: C++ programmers will not like that you use a struct with the same name as a function. In a document about C, there's not much reason to care whether C++ programmers will like it or not. On the other hand, C programmers may dislike it because it's confusing, even if it's perfectly legal.
I was being conservative. I imagine /some/ C programmers would like it,
and not think it's confusing at all --- I see why the OP did it, since the
struct is only being used in conjunction with that one function. But it
might confuse C programmers who are /also/ C++ programmers. :)
<OT> Some languages, such as Perl and Ada, only support comments introduced by a delimiter and terminated by the end of a line. Personally, I like that better than C's "/* ... */" comments. If "//" comments were portable in C, I'd probably use them in preference to "/* ... */" comments. YMMV. </OT>
MMDV, yes. Too many formatting pitfalls; also, I like to write block
comments and dislike too many scattered single-line comments. 6: "programmin g ... is not the place to express creativity ..." Obviously you have never programmed!
But there is a valid point there. Certain forms of "creativity " are inappropriate. (I'd expound further if I had time.)
Certain forms, yeah, but that's a different point. The OP's sentence
was as ridiculous as claiming that "literature is no place for creativity"
just because some people can't spell right!
-Arthur
On Sun, 05 Dec 2004 05:11:38 +0000, Rouben Rostamian wrote: In article <pa************ *************** *@pldaniels.com >, Paul L Daniels <pl*******@plda niels.com> wrote:Hello All,
I've been compiling a series of pages about the bad functions and mistakes that occur in C into a book, subsequently, I now have a moderate little book of about 32 pages available for download as a PDF file at
http://www.pldaniels.com/c-of-peril
It's currently still being worked on and I'm always seeking out new examples of C being used poorly or broken standard functions.
I looked quickly through your writeup. It's pretty good. Here are my remarks on a couple of items that sort of jumped at me.
1. On the section on free() you wrote:
Certainly it is agreeable that if you are attempting to free a null pointer, then you're most certainly in a situation where somewhere prior in your code there is something amiss.
Certainly it is agreeable? Not!
I free() NULL pointers frequently and intentionally. Here is a sample:
You are aware this will utterly fuck up things on many platforms ?
I wouldn't advocate this knowing that it may break if I were you ...
Nils O. Selåsdal wrote: On Sun, 05 Dec 2004 05:11:38 +0000, Rouben Rostamian wrote:
[snip] I free() NULL pointers frequently and intentionally. Here is a sample:
You are aware this will utterly fuck up things on many platforms ? I wouldn't advocate this knowing that it may break if I were you ...
Please:
<Quote>
The C standard page 312
7.20.3.2 The free function
Synopsis
1 #include <stdlib.h>
void free(void *ptr);
Description
2 The free function causes the space pointed to by ptr to be
deallocated, that is, made available for further allocation.
If ptr is a null pointer, no action occurs.
</quote>
In article <pa************ *************** *@Utel.no>,
Nils O. Selåsdal <NO*@Utel.no> wrote: On Sun, 05 Dec 2004 05:11:38 +0000, Rouben Rostamian wrote: I free() NULL pointers frequently and intentionally. Here is a sample: You are aware this will utterly fuck up things on many platforms ? I wouldn't advocate this knowing that it may break if I were you ...
free(NULL) is perfectly harmless; it's required to be so by
the C standard.
If your platform is broken, change the platform. Don't ask
me to change my good code to accommodate your bad platform.
--
Rouben Rostamian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: anonymous |
last post by:
Hi CLCers,
I want to know your opinion about the book: Expert C
programming-Deep C secrets by Peter Van Der Linden. Thanks
in advance.
Sha
|
by: Guido Mureddu |
last post by:
Hello,
I'm a student in electronic engineering. I do know you've seen and answered this
sort of topic/request countless times, but I haven't found past threads as
helpful as I had hoped, and even though I have read them all and many reviews, I
prefer to ask directly to people who know the subject better than anyone else.
First of all, I'm not new to programming, and I have already had an
introductory course on C. I have an...
|
by: Robert Zurer |
last post by:
Can anyone suggest the best book or part of a book on this subject. I'm
looking for an in-depth treatment with examples in C#
TIA
Robert Zurer
robert@zurer.com
|
by: Dgates |
last post by:
Has anyone typed up an index for the O'Reilly book "C# and VB.NET
Conversion?"
I'm just learning C#, and often using this little book to see which
VB.NET terms translate directly to some term in C#. However, it's a
real hassle that the book has no index, just a table of contents.
For example, as early as page 8, the book teaches that C#'s "using"
statement is the equivalent of VB.NET's "imports" statement. However,
that concept...
|
by: www.douglassdavis.com |
last post by:
I'm looking for advice here, and I would really appreciate it if you
could help.
Is there a VB 2005 book that you like and would recommend (and why)?
Would you consider it good for beginners to programming, intermediate,
or advanced level?
| |
by: Malcolm McLean |
last post by:
The webpages for my new book are now up and running.
The book, Basic Algorithms, describes many of the fundamental algorithms
used in practical programming, with a bias towards graphics. It includes
mathematical routines from the basics up, including floating point
arithmetic, compression techniques, including the GIF and JPEG file formats,
hashing, red black trees, 3D and 3D graphics, colour spaces, machine
learning with neural...
|
by: Hello |
last post by:
Hello every body
Please can any body tells me a good book that can teach me "visual basic 2005" (as beginner).
Thank you all
=========================================
|
by: jrw133 |
last post by:
i got this program the other day and ive just started it and i am getting some errors that i cant figure out.
requirements: 1)create a clas called Book. a Book has three data members: m_title, m_id and m_flag to tell whether the book is in or checked out. 2)Write a constructor for Book. write a constructor that takes 3 parameters: Book(char * title, int id, bool flag) and initializes the 3 data members accordingly. in addition print out a...
|
by: lorlarz |
last post by:
Crockford's JavaScript, The Good Parts (a book review).
This shall perhaps be the world's shortest book review (for one of the
world's
shortests books).
I like Douglas Crockford (because I am a crabby old man too; plus he
_is_
smart and good).. But, how can he write a book on the good parts of
JavaScript
and not mention functions that address CSS & DOM? Weird. It's like
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |