register char *p1, *p2; sind uninitialisiert, genau wie *b1, *b2 und len liegen die Variablen im Stack, klar haben die eine gewisse Größe im Speicher, aber keine signifikante. Es geht um die Lesbarkeit der Funktion damit man sich einen guten Überblick beschaffen kann. Hier ist ein Beispiel wie Apple bcmp(...) implementiert hat: Source
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.1 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if !defined(__ppc__)
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)bcmp.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <string.h>
/*
* bcmp -- vax cmpc3 instruction
*/
int
bcmp(b1, b2, length)
const void *b1, *b2;
register size_t length;
{
register char *p1, *p2;
if (length == 0)
return(0);
p1 = (char *)b1;
p2 = (char *)b2;
do
if (*p1++ != *p2++)
break;
while (--length);
return(length);
}
#else
#warning ----------- Check for implementation of bcmp() ----------- !
#endif /* !defined(__ppc__) */
Alles anzeigen
Nginx nutzt denselben Style um die Readability zu garantieren: Source
ngx_fd_t
ngx_open_file(u_char *name, u_long mode, u_long create, u_long access)
{
size_t len;
u_short *u;
ngx_fd_t fd;
ngx_err_t err;
u_short utf16[NGX_UTF16_BUFLEN];
len = NGX_UTF16_BUFLEN;
u = ngx_utf8_to_utf16(utf16, name, &len);
if (u == NULL) {
return INVALID_HANDLE_VALUE;
}
fd = INVALID_HANDLE_VALUE;
if (create == NGX_FILE_OPEN
&& ngx_win32_check_filename(name, u, len) != NGX_OK)
{
goto failed;
}
fd = CreateFileW(u, mode,
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL);
failed:
if (u != utf16) {
err = ngx_errno;
ngx_free(u);
ngx_set_errno(err);
}
return fd;
}
Alles anzeigen
Im Endeffekt kann man seine Funktionen so gestalten wie es demjenigen lieb ist, aber ich persönlich finde es halt cooler und schöner wenn man einen gewissen Style verwendet der eben auch die Readability verdeutlicht und den nächsten Entwicklern die Weiterentwicklung erleichtert. Gerade bei Open Source Projekten ist das vom Vorteil. Ob du jetzt aufhören willst zu lesen ist ja deine persönliche Sache, ist garantiert keiner wütend gegenüber deiner Meinung aber falls du fragen hast werde ich sie dir auf alle Fälle beantworten.
@Everyone, tut mir leid dass ich den Thread nicht derzeitig verbessern kann. Es fehlt mir leider an Zeit, aber definitiv werden hier noch #Updates dazu kommen.
Wünsche Euch viel Spaß beim programmieren.