[ProgClub list] Memory management in C

John Elliot jj5 at progclub.org
Sun Oct 2 04:38:21 AEDT 2011

On 2/10/2011 4:28 AM, Asher Glynn wrote:
> The real condemnation (for me) is around using libraries in C - even if you
> are a good C developer, you'll get a hell of a shock when you go to look at
> some APIs...

I'm just starting to discover that myself. For instance, the other day I 
learned how to set socket options and it's with an API call like this:

   struct linger linger;
   linger.l_onoff = 1;
   linger.l_linger = 5;
   if ( setsockopt( conn_s, SOL_SOCKET, SO_LINGER, &linger, sizeof( 
linger ) ) < 0 ) {
     fprintf( stderr, "Error setting socket option.\n" );
     exit( EXIT_FAILURE );

How nasty is that!?

The setsockopt function takes a few parameters and then a void pointer 
to its option-specific argument the content of which it must interpret 
based on what other parameters you've specified.


I have no doubt that some APIs are even worse than this.

More information about the list mailing list