From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 5DE5D4AC72 for ; Sat, 18 May 2024 17:03:12 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 42B1968CDFE; Sat, 18 May 2024 20:03:09 +0300 (EEST) Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B2F4468CA8A for ; Sat, 18 May 2024 20:03:03 +0300 (EEST) Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-51ff65b1e14so3434497e87.2 for ; Sat, 18 May 2024 10:03:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716051782; x=1716656582; darn=ffmpeg.org; h=subject:date:from:to:message-id:from:to:cc:subject:date:message-id :reply-to; bh=hOMVLEDPRCmzsidcGVOqqkY8nTnGG4CUoDz6QTb3KaA=; b=gmX3aC+wQTa6VPMFBydt4lSLGCuR9LNxnqXYTsnqVmzPwgRpsF4/UTwyCGCRUUpng9 PnyWgZZcWG0AvqdVFTheFeR8TMGpTpL0D25WZtbdA1GqU0JDboPSfHPzj3qsBY/6oRhu ORGCl60pkJZulv2Xai10sU04mRG3AaMydUgz58zJyPQVR/+k7fWLQxbr0C6gY/RETel8 f7OBk3C/Q0zOP+j+b+SQEFIETbN2In1yOJgUc8SVuLsDNqdrIQTcp6e+ZS3MtPTIxEz/ vBR3wmibMQqvrE7FEPY+28Y298JdVTr7cMiMaG+gVCk0cRBfjhqVClaOD4lU8lAX+CLA KY6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716051782; x=1716656582; h=subject:date:from:to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hOMVLEDPRCmzsidcGVOqqkY8nTnGG4CUoDz6QTb3KaA=; b=bq+QzrUQUumO1CHs+obTapYk3/UQTlECMn4mmr8hDQe6U2pLPE8FjR4jrk/DThTnzM 5nAD8hNFTUb8hqpZADiLZ1IGu3welA/Xti/KgG6xpCU9dCRmIfZL9zbo988uhcuRj9Sz o4mhCyoStV0Bw/KC6BiUqxUx/WEQQ9OXZVPSzP4V7AqzeVYsN6MQPhlUgvWKln877tSs iBhNo7reR2gSXX5Wks/G4avrRxLnG2NlPNSrdPRp0zdLHMg/HrtucmQg/xfgzl7p7NYS Im9S1vc2Dx8hG+QIHRWI4w1Z3iQtjYY4LtyUAuUstnwCY4cq4CNCVOu055JPXwMWamLX EwVA== X-Gm-Message-State: AOJu0YyiEiiCLe+3P2n7X2qcBHC0EXq1YcPillaShY4BzCzKt9Uednjx BRS/vBjT6jnjRRVdTH0aKc14y1Wio9G/qjjyFVaP7Y8KW9ouYBUVRRw75Q== X-Google-Smtp-Source: AGHT+IGEu0dCrjCqSJ3PRUZisuXuAevkcEDyoyker4PAEEnRiShU/Nn/0p6Zv52c/bjdxtX9LK4DLg== X-Received: by 2002:a05:6512:b81:b0:51e:f7de:d8eb with SMTP id 2adb3069b0e04-5220fb76879mr20826424e87.10.1716051782048; Sat, 18 May 2024 10:03:02 -0700 (PDT) Received: from localhost (dynamic-2a01-0c23-5cdf-1c00-28f3-4e89-826e-7677.c23.pool.telefonica.de. [2a01:c23:5cdf:1c00:28f3:4e89:826e:7677]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b015besm1258793766b.144.2024.05.18.10.03.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 18 May 2024 10:03:00 -0700 (PDT) Message-Id: To: From: "Marvin Scholz" Date: Sat, 18 May 2024 19:00:50 +0200 Subject: [FFmpeg-devel] [PATCH] doc/developer: add examples to clarify code style X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Given the frequency that new developers, myself included, get the code style wrong, it is useful to add some examples to clarify how things should be done. --- doc/developer.texi | 57 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/doc/developer.texi b/doc/developer.texi index 63835dfa06..d7bf3f9cb8 100644 --- a/doc/developer.texi +++ b/doc/developer.texi @@ -115,7 +115,7 @@ Objective-C where required for interacting with macOS-specific interfaces. @section Code formatting conventions -There are the following guidelines regarding the indentation in files: +There are the following guidelines regarding the code style in files: @itemize @bullet @item @@ -135,6 +135,61 @@ K&R coding style is used. @end itemize The presentation is one inspired by 'indent -i4 -kr -nut'. +@subsection Examples +Some notable examples to illustrate common code style in FFmpeg: + +@itemize @bullet + +@item +Spaces around @code{if}/@code{do}/@code{while}/@code{for} conditions and assigments: + +@example c +if (condition) + av_foo(); +@end example + +@example c +for (size_t i = 0; i < len; i++) + av_bar(i); +@end example + +@example c +size_t size = 0; +@end example + +However no spaces between the parentheses and condition, unless it helps +readability of complex conditions, so the following should not be done: + +@example c +// Wrong: +if ( cond ) + av_foo(); +@end example + +@item +No unnecessary parentheses, unless it helps readability: + +@example c +flags = s->mb_x ? RIGHT_EDGE : LEFT_EDGE | RIGHT_EDGE; +@end example + +@item +No braces around single-line blocks: + +@example c +if (bits_pixel == 24) + avctx->pix_fmt = AV_PIX_FMT_BGR24; +else if (bits_pixel == 8) + avctx->pix_fmt = AV_PIX_FMT_GRAY8; +else @{ + av_log(avctx, AV_LOG_ERROR, "Invalid pixel format.\n"); + return AVERROR_INVALIDDATA; +@} +@end example + +@end itemize + + @subsection Vim configuration In order to configure Vim to follow FFmpeg formatting conventions, paste the following snippet into your @file{.vimrc}: base-commit: 86e418ffd7bbdc0530e1e4d5bd7534b6e03b5b05 -- 2.39.3 (Apple Git-145) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".