473,804 Members | 3,941 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New book - 'C of Peril'

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 2608
Keith Thompson <ks***@mib.or g> writes:
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> writes:

[...]
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.)


What I was thinking of was number 8 from Henry Spencer's "The Ten
Commandments for C Programmers":

Thou shalt make thy program's purpose and structure clear to thy
fellow man by using the One True Brace Style, even if thou likest
it not, for thy creativity is better used in solving problems than
in creating beautiful new impediments to understanding.

(The "One True Brace Style" refers to the style used in K&R; even if
you prefer a different style, the point is a good one.)

<http://www.lysator.liu .se/c/ten-commandments.ht ml>

(Certainly the idea that programming is not the place to express
creativity is ludicrous. Programming isn't just an art, but neither
is it a science; it's a craft.)

--
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.
Nov 14 '05 #21
Nils O. Selåsdal <NO*@Utel.no> writes:
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 f*** up things on many platforms ?
I wouldn't advocate this knowing that it may break if I were you ...


[edited for content]

Many platforms? Name three.

--
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.
Nov 14 '05 #22

"jacob navia" <ja***@jacob.re mcomp.fr> wrote in message
news:41******** *************** @news.wanadoo.f r...

<snip>
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.


Introducing Garbage Collection in C wil render the language useless to any
application-developer in need of (hard) Real Time. That *would* be a pity.
Nov 14 '05 #23
dandelion wrote:
"jacob navia" <ja***@jacob.re mcomp.fr> wrote in message
news:41******** *************** @news.wanadoo.f r...

<snip>
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.

Introducing Garbage Collection in C wil render the language useless to any
application-developer in need of (hard) Real Time. That *would* be a pity.

There is no "introducti on of garbage collection" in the language itself!

The standard library isn't changed either.

The only thing that changes is

#define malloc(a) GC_malloc(a)
#define free(a)

There are no language modifications whatsoever.

jacob
Nov 14 '05 #24

"jacob navia" <ja***@jacob.re mcomp.fr> wrote in message
news:41******** *************** @news.wanadoo.f r...
dandelion wrote:
"jacob navia" <ja***@jacob.re mcomp.fr> wrote in message
news:41******** *************** @news.wanadoo.f r...

<snip>
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.

Introducing Garbage Collection in C wil render the language useless to any application-developer in need of (hard) Real Time. That *would* be a pity.

There is no "introducti on of garbage collection" in the language itself!

The standard library isn't changed either.

The only thing that changes is

#define malloc(a) GC_malloc(a)
#define free(a)

There are no language modifications whatsoever.


And the garbage collection routine? At some point some GC will need to
be done.

Nov 14 '05 #25
dandelion wrote:
"jacob navia" <ja***@jacob.re mcomp.fr> wrote in message
news:41******** *************** @news.wanadoo.f r...
dandelion wrote:
"jacob navia" <ja***@jacob.re mcomp.fr> wrote in message
news:41***** *************** ***@news.wanado o.fr...

<snip>

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.
Introducin g Garbage Collection in C wil render the language useless to
any
applicatio n-developer in need of (hard) Real Time. That *would* be a
pity.

There is no "introducti on of garbage collection" in the language itself!

The standard library isn't changed either.

The only thing that changes is

#define malloc(a) GC_malloc(a)
#define free(a)

There are no language modifications whatsoever.

And the garbage collection routine? At some point some GC will need to
be done.


It is done at each allocation.
There are several levels: mini-gcs, full gc, etc.
Nov 14 '05 #26
jacob navia wrote:
dandelion wrote:
"jacob navia" <ja***@jacob.re mcomp.fr> wrote in message

<snip>
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.


Introducing Garbage Collection in C wil render the language
useless to any application-developer in need of (hard) Real Time.
That *would* be a pity.

There is no "introducti on of garbage collection" in the language itself!

The standard library isn't changed either.

The only thing that changes is

#define malloc(a) GC_malloc(a)
#define free(a)

There are no language modifications whatsoever.


Those redefinitions are specifically forbidden by the standard, and
for good reasons, which in turn should be obvious to any
implementor.

--
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!
Nov 14 '05 #27
CBFalconer wrote:
jacob navia wrote:
The only thing that changes is

#define malloc(a) GC_malloc(a)
#define free(a)

There are no language modifications whatsoever.

Those redefinitions are specifically forbidden by the standard, and
for good reasons, which in turn should be obvious to any
implementor.


That is in the case you want to replace all your calls to
malloc with the gc (a sensible solution)

You are not forced to do that, since you can always explicitely
call GC_malloc. You should never call free however, because if
you call free with a GC_malloced object chaos will ensue.

Those errors can be very difficult to catch, hence the proposed defines.
jacob
Nov 14 '05 #28
jacob navia <ja***@jacob.re mcomp.fr> writes:
dandelion wrote:
"jacob navia" <ja***@jacob.re mcomp.fr> wrote in message
news:41******** *************** @news.wanadoo.f r...
<snip>
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.

Introducing Garbage Collection in C wil render the language useless
to any
application-developer in need of (hard) Real Time. That *would* be a pity.

There is no "introducti on of garbage collection" in the language itself!

The standard library isn't changed either.

The only thing that changes is

#define malloc(a) GC_malloc(a)
#define free(a)

There are no language modifications whatsoever.


Apart from the legality questions of redefining malloc(), wouldn't you
want a GC_free() routine as well? After free(a), the variable "a"
will still contain a copy of the (now indeterminate) pointer.
Presumably that would prevent the garbage collector from collecting
memory indirectly pointed to by "a". (The program could set a to
NULL, but that's an extra requirement.)

It's not true that there are no language modifications whatsoever.
Values, including pointers, are made of bytes, which are made of bits.
A strictly conforming program can convert a pointer to an array of
unsigned char, destroy the original pointer value, complement the
unsigned char values, go off and do some other stuff, then reconsitute
the pointer from the scrambled bytes and dereference it. If GC is
being used, once the pointer value doesn't exist in its original form
the system can deallocate whatever it points to.

That's not to say that it would be unreasonable to provide garbage
collection in a C implementation, but it would be a change in the
semantics of the language.

--
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.
Nov 14 '05 #29
Keith Thompson wrote:
jacob navia <ja***@jacob.re mcomp.fr> writes:
dandelion wrote:
"jacob navia" <ja***@jacob.re mcomp.fr> wrote in message
news:41***** *************** ***@news.wanado o.fr...
<snip>

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.

Introducin g Garbage Collection in C wil render the language useless
to any
applicatio n-developer in need of (hard) Real Time. That *would* be a pity.

There is no "introducti on of garbage collection" in the language itself!

The standard library isn't changed either.

The only thing that changes is

#define malloc(a) GC_malloc(a)
#define free(a)

There are no language modifications whatsoever.

Apart from the legality questions of redefining malloc(), wouldn't you
want a GC_free() routine as well? After free(a), the variable "a"
will still contain a copy of the (now indeterminate) pointer.
Presumably that would prevent the garbage collector from collecting
memory indirectly pointed to by "a". (The program could set a to
NULL, but that's an extra requirement.)


There *is* a GC_free routine, but its use is not really recommended.
Sometimes it can be useful to use it when you are 100% sure that a
memory block will never be used again.

If we would have to use GC_free, the utility of an automatic GC would
be greatly reduced...

It's not true that there are no language modifications whatsoever.
Values, including pointers, are made of bytes, which are made of bits.
A strictly conforming program can convert a pointer to an array of
unsigned char, destroy the original pointer value, complement the
unsigned char values, go off and do some other stuff, then reconsitute
the pointer from the scrambled bytes and dereference it. If GC is
being used, once the pointer value doesn't exist in its original form
the system can deallocate whatever it points to.

If you use the GC you have to leave the bits in the pointers as they
are. If you hide them, the block could be collected if there are no
other references to it.

This is a "change" in the way you use pointers (maybe, the case you
mention is highly hypotetical), since you can't store them on disk,
or in the "windows extra bytes" (where the collector doesn't look),
or Xor them and expect the pointer to still be valid afterwards.

This is a limitation of the collector/compiler.

A clever compiler would see what you are doing and store a hidden copy
of the pointer somewhere :-)
That's not to say that it would be unreasonable to provide garbage
collection in a C implementation, but it would be a change in the
semantics of the language.


The fact that you shouldn't store the pointers to live objects in
the disk or change their value is a "semantic change to the language" ???

Those kind of operations with pointers are quite rare, and I have
never seen them. But yes, if you insist, there *are* some limitations
and constraints imposed to you, as with any other software that you use.

For 99.9999 % of the applications, where pointers are stored normally
in local variables or in data structures, nothing changes.

Please bear in mind that I am not telling "GC is the best thing since
sliced bread". I am not a salesman. The GC can be useful in many
applications and relieves you from the terrible problems of making
errors in malloc/free, what is a big advantage.

But it can produce errors if you keep unneeded pointers around, errors
that are very difficult to track! I would not recommend it in real
time systems either, but those systems do not use even the "malloc"
system call anyway.

In many PC applications however, it gives the C language a huge
advantage, simplifying the applications, simplifying the programming.

jacob
Nov 14 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2430
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
12
2125
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...
16
8514
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
8
2199
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...
11
1934
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?
263
9415
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...
6
1992
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 =========================================
1
3594
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...
76
4100
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
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10583
Oralloy
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...
0
10337
jinu1996
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...
0
10082
tracyyun
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...
1
7622
isladogs
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...
0
6854
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();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4301
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
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.