Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: What is "complexifying" C? |
| Date | 2015-03-23 17:25 +1300 |
| Message-ID | <cn9itjF9hh7U3@mid.individual.net> (permalink) |
| References | (11 earlier) <3dingapi21g9aj30pel30s2288h02r5c0g@4ax.com> <cn24hhF9khqU2@mid.individual.net> <3cb9b37a-d3fa-478b-b116-bbb737753cc8@googlegroups.com> <cn6i19FdhbaU1@mid.individual.net> <leak-20150322234843@ram.dialup.fu-berlin.de> |
Stefan Ram wrote:
> Ian Collins <ian-news@hotmail.com> writes:
>> It certainly is not a bad idea, it is one of the most useful tools in
>> the C++ toolbox. Amongst other things, it makes resource leaks a thing
>> of the past.
>
> Where is the resource leak in the following C code?
>
> (The entry point is the function »f« at the bottom.
> This is from a previous post I wrote in this NG as
> a reply; that's where the »f« comes from.«
>
> The order of the following functions is »bottom up«.)
Does it matter? The point I was making is RAII removes the burden of
resource management from the user of the managing object.
> static inline int copy
> ( char const * const x, char * const a, char * const b )
> { int const success = 1; strcpy( a, x ); strcpy( b, x );
> strcpy( b + 255, a ); return success; }
>
> static inline int allocate_second_buffer
> ( char const * const x, char * const a )
> { int success = 0; char * const buffer = malloc( 2 * 256 );
> if( buffer ){ success = copy( x, a, buffer ); free( buffer ); }
> return success; }
>
> static inline int allocate_first_buffer
> ( char const * const x )
> { int success = 0; char * const buffer = malloc( 256 );
> if( buffer )
> { success = allocate_second_buffer( x, buffer );
> free( buffer ); }
> return success; }
>
> static inline int check_x( char const * const x )
> { int success = 0; if( x )success = allocate_first_buffer( x );
> return success; }
>
> static inline int check_l( char const * const x, int const l )
> { int success = 0; if( l <= 255 )success = check_x( x );
> return success; }
>
> int f( char const * const x, int const l )
> { return check_l( x, l ); }
>
> Does it look much harder to read or to write than the
> equivalent C++?
The lack of white-space is what makes it hard to read!
If I get the gist of what you have written, the C++ might look something
like:
int
f( char const* const x, int l )
{
if( l > 255 ) return 0;
std::unique_ptr<char> buffer1( new char[256] );
std::unique_ptr<char> buffer2( new char[2*256] );
return copy( x, buffer1.get(), buffer2.get() );
}
--
Ian Collins
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-16 22:55 +0100
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-16 22:55 +0000
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-16 16:41 -0700
Re: What is "complexifying" C? Richard Heathfield <rjh@cpax.org.uk> - 2015-03-17 00:05 +0000
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-17 01:12 +0000
Re: What is "complexifying" C? Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-25 13:58 -0700
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 07:16 +0100
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-17 13:50 +0000
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 14:59 +0100
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 15:22 +0100
Re: What is "complexifying" C? David Brown <david.brown@hesbynett.no> - 2015-03-17 16:16 +0100
Re: What is "complexifying" C? Kaz Kylheku <kaz@kylheku.com> - 2015-03-17 14:39 +0000
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-17 15:23 +0000
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-18 15:40 -0700
Re: What is "complexifying" C? Kaz Kylheku <kaz@kylheku.com> - 2015-03-18 22:49 +0000
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-19 13:55 +0000
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-19 15:37 +0000
Re: What is "complexifying" C? jacob navia <jacob@jacob.remcomp.fr> - 2015-03-19 23:06 +0100
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-19 22:38 +0000
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-20 19:43 +1300
Re: What is "complexifying" C? jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 07:49 +0100
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 02:29 -0500
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-20 21:37 +1300
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 03:40 -0500
Re: What is "complexifying" C? David Brown <david.brown@hesbynett.no> - 2015-03-20 10:18 +0100
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-21 00:19 -0500
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-20 03:15 -0700
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-22 13:51 +1300
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-22 15:21 +1300
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-22 00:57 -0700
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-22 22:28 +1300
Re: What is "complexifying" C? fir <profesor.fir@gmail.com> - 2015-03-22 02:59 -0700
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-22 11:16 -0700
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 07:25 +1300
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-22 12:06 -0700
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 17:01 +1300
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-23 03:09 -0700
Re: What is "complexifying" C? fir <profesor.fir@gmail.com> - 2015-03-23 01:42 -0700
Re: What is "complexifying" C? Melzzzzz <mel@zzzzz.com> - 2015-03-22 19:32 +0100
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-22 17:34 -0500
Re: What is "complexifying" C? Richard Damon <Richard@Damon-Family.org> - 2015-03-22 20:07 -0400
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-23 00:00 -0500
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 18:04 +1300
Re: What is "complexifying" C? Richard Damon <Richard@Damon-Family.org> - 2015-03-23 23:22 -0400
Re: What is "complexifying" C? Richard Damon <Richard@Damon-Family.org> - 2015-03-22 14:54 -0400
Re: What is "complexifying" C? Melzzzzz <mel@zzzzz.com> - 2015-03-23 00:35 +0100
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 17:06 +1300
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 17:25 +1300
Re: What is "complexifying" C? Martin Shobe <martin.shobe@yahoo.com> - 2015-03-22 23:33 -0500
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 18:01 +1300
Re: What is "complexifying" C? James Kuyper <jameskuyper@verizon.net> - 2015-03-23 09:41 -0400
Re: What is "complexifying" C? James Kuyper <jameskuyper@verizon.net> - 2015-03-23 10:23 -0400
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-24 07:10 +1300
Re: What is "complexifying" C? James Kuyper <jameskuyper@verizon.net> - 2015-03-23 14:57 -0400
Re: What is "complexifying" C? David Brown <david.brown@hesbynett.no> - 2015-03-24 09:36 +0100
Re: What is "complexifying" C? Richard Heathfield <rjh@cpax.org.uk> - 2015-03-24 08:42 +0000
Re: What is "complexifying" C? David Brown <david.brown@hesbynett.no> - 2015-03-24 11:23 +0100
Re: What is "complexifying" C? Richard Heathfield <rjh@cpax.org.uk> - 2015-03-24 10:52 +0000
Re: What is "complexifying" C? raltbos@xs4all.nl (Richard Bos) - 2015-03-29 16:58 +0000
Re: What is "complexifying" C? Melzzzzz <mel@zzzzz.com> - 2015-03-22 02:38 +0100
Re: What is "complexifying" C? Richard Damon <Richard@Damon-Family.org> - 2015-03-22 09:11 -0400
Re: What is "complexifying" C? Les Cargill <lcargill99@comcast.com> - 2015-03-20 06:30 -0500
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-20 10:31 +0000
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-20 13:49 +0000
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-20 09:23 -0700
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-21 08:28 +1300
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-20 01:04 -0700
Re: What is "complexifying" C? Keith Thompson <kst-u@mib.org> - 2015-03-17 08:05 -0700
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 16:08 +0100
Re: What is "complexifying" C? Keith Thompson <kst-u@mib.org> - 2015-03-17 11:09 -0700
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 21:37 +0100
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-18 00:40 -0500
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-17 15:34 +0000
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-17 15:06 +0000
Re: What is "complexifying" C? Melzzzzz <mel@zzzzz.com> - 2015-03-17 00:05 +0100
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-16 23:20 +0000
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-17 16:42 +1300
Re: What is "complexifying" C? Mark Storkamp <mstorkamp@yahoo.com> - 2015-03-17 08:59 -0500
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 15:18 +0100
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-17 14:41 +0000
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-18 15:47 -0700
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-19 00:26 +0000
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-19 03:23 -0700
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-19 11:19 +0000
csiph-web