[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
 

Programmering, kode-stil, indent, flere return



Hej

Spørgsmålet skulle nok have været på prorammeringslisten, men da det er
lidt for langt ude af en tangent, så hører det nok hjemme her.

Må man have flere "return/exit" i en funktion? Må man udføre den sammme
operation to eller flere gange i samme funktion? Hvor mange indent må
der være i en funktion? Må en funktion være 2 skærmsider lang?

Kodestil er jo ikke eksakt videnskab, så holdninger ønskes:
(det er hensigten at de 2 eksempler skulle gøre det samme)
-----------------------------------------------------------------------
int ex1() {
	char * p1;
	char * p2;
	char * p3;
	int n = 0;
	p1 = malloc(256);
	if (!p1) {
		return 0;
	}
	fill_with_data_1(p1);
	p2 = malloc(256);
	if (!p2) {
		free(p1);
		return 0;
	}
	fill_with_data_2(p2);
	p3 = malloc(256);
	if (!p3) {
		free(p2);
		free(p1);
		return 0;
	}
	fill_with_data_3(p3);
	n = mixit(p1,p2,p3);
	free(p3);
	free(p2);
	free(p1);
	return n;
}

int ex2() {
	char * p1;
	char * p2;
	char * p3;
	int n = 0;
	p1 = malloc(256);
	if (p1) {
		fill_with_data_1(p1);
		p2 = malloc(256);
		if (p2) {
			fill_with_data_2(p2);
			p3 = malloc(256);
			if (p3) {
				fill_with_data_3(p3);
				n = mixit(p1,p2,p3);
				free(p3);
			}
			free(p2);
		}
		free(p1);
	}
	return n;
}

/hans
-- 
Q: Hey, Johnny, What are you rebelling against?
A: What've you got?



 
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] *