[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [MISC] Programmering, kode-stil, indent, flere return



In <sslug@sslug> Hans Schou <sslug@sslug> writes:

>int ex4() {
>	char * p1;
>	char * p2;
>	char * p3;
>	int n = 0;
>	if (!p1 = malloc(256)) {
>		return -1;
>	} /* if malloc p1 */
>	do_something_1(p1);
>	if (!p2 = malloc(256)) {
>		free(p1);
>		return -2;
>	} /* if malloc p2 */
>	do_something_2(p1,p2);
>	if (!p3 = malloc(256)) {
>		free(p2);
>		free(p1);
>		return -3;
>	} /* if malloc p3 */
>	n = do_something_3(p1,p2,p3);
>	free(p3);
>	free(p2);
>	free(p1);
>	return n;
>}


Vi er ude i "smag og behag" afdelingen. Det jeg bare er rendt ind i
nogle gange med den måde at strukturere koden på, er at det er svært
at arbejde videre med. Hvis nu du finder ud af at du skal have noget
sat ind umiddelbart efter "do_something_1(p1);" kaldet - noget hvor du 
også allokerer mere memory - så skal du dels skrive den nye kode, og 
dels rette tre steder for at få lavet alle dine free's af den ekstra 
blok memory du allokerer i den nye kode.


Henrik



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-03-01, 02:04 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *