En Norm
En Norm
Version 3
II The Norm 3
II.1 Denomination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
II.2 Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
II.3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
II.4 Typedef, struct, enum and union . . . . . . . . . . . . . . . . . . . . . 7
II.5 Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
II.6 Macros and Pre-processors . . . . . . . . . . . . . . . . . . . . . . . . 9
II.7 Forbidden stuff! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
II.8 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
II.9 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
II.10 Makefile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1
Chapter I
Foreword
2
Chapter II
The Norm
II.1 Denomination
• A structure’s name must start by s_.
• Variables and functions names can only contain lowercases, digits and ’_’ (Unix
Case).
• Files and directories names can only contain lowercases, digits and ’_’ (Unix Case).
• Characters that aren’t part of the standard ASCII table are forbidden.
• Variables, functions, and any other identifier must use snake case. No capital letters,
and each word separated by an underscore.
• Objects (variables, functions, macros, types, files or directories) must have the most
explicit or most mnemonic names as possible.
• Using global variables that are not marked const and static is forbidden and is
considered a norm error, unless the project explicitly allows them.
• The file must compile. A file that doesn’t compile isn’t expected to pass the Norm.
3
The Norm Version 3
II.2 Formatting
• You must indent your code with 4-space tabulations. This is not the same as 4
average spaces, we’re talking about real tabulations here.
• Each function must be maximum 25 lines, not counting the function’s own curly
brackets.
• Each line must be at most 80 columns wide, comments included. Warning: a
tabulation doesn’t count as a column, but as the number of spaces it represents.
• Each function must be separated by a newline. Any comment or preprocessor
instruction can be right above the function. The newline is after the previous
function.
• One instruction per line.
• An empty line must be empty: no spaces or tabulations.
• A line can never end with spaces or tabulations.
• You can never have two consecutive spaces.
• You need to start a new line after each curly bracket or end of control structure.
• Unless it’s the end of a line, each comma or semi-colon must be followed by a space.
• Each operator or operand must be separated by one - and only one - space.
• Each C keyword must be followed by a space, except for keywords for types (such
as int, char, float, etc.), as well as sizeof.
• Each variable declaration must be indented on the same column for its scope.
• The asterisks that go with pointers must be stuck to variable names.
• One single variable declaration per line.
• Declaration and an initialisation cannot be on the same line, except for global
variables (when allowed), static variables, and constants.
• Declarations must be at the beginning of a function.
• In a function, you must place an empty line between variable declarations and the
remaining of the function. No other empty lines are allowed in a function.
• Multiple assignments are strictly forbidden.
• You may add a new line after an instruction or control structure, but you’ll have
to add an indentation with brackets or assignment operator. Operators must be at
the beginning of a line.
• Control structures (if, while..) must have braces, unless they contain a single line.
• Braces following functions, declarators or control structures must be preceded and
followed by a newline.
4
The Norm Version 3
General example:
int g_global;
typedef struct s_struct
{
char *my_string;
int i;
} t_struct;
struct s_other_struct;
int main(void)
{
int i;
char c;
return (i);
}
5
The Norm Version 3
II.3 Functions
• A function can take 4 named parameters maximum.
• A function that doesn’t take arguments must be explicitly prototyped with the
word "void" as the argument.
• Each function must have a single tabulation between its return type and its name.
int func2(void)
{
return ;
}
6
The Norm Version 3
• When declaring a variable of type struct, enum or union, add a single space in the
type.
• When declaring a struct, union or enum with a typedef, all indentation rules apply.
• You must indent all structures’ names on the same column for their scope.
7
The Norm Version 3
II.5 Headers
• The things allowed in header files are: header inclusions (system or not), declara-
tions, defines, prototypes and macros.
• Header files must be protected from double inclusions. If the file is ft_foo.h, its
bystander macro is FT_FOO_H.
#ifndef FT_HEADER_H
# define FT_HEADER_H
# include <stdlib.h>
# include <stdio.h>
# define FOO "bar"
int g_variable;
struct s_struct;
#endif
8
The Norm Version 3
• All #define created to bypass the norm and/or obfuscate code are forbidden. This
part must be checked by a human.
• You can use macros available in standard libraries, only if those ones are allowed
in the scope of the given project.
9
The Norm Version 3
◦ for
◦ do...while
◦ switch
◦ case
◦ goto
10
The Norm Version 3
II.8 Comments
• Comments cannot be inside functions’ bodies. Comments must be at the end of a
line, or on their own line
11
The Norm Version 3
II.9 Files
• You cannot include a .c file.
12
The Norm Version 3
II.10 Makefile
Makefiles aren’t checked by the Norm, and must be checked during evaluation by the
student.
• In the case of a multibinary project, in addition to the above rules, you must have a
rule that compiles both binaries as well as a specific rule for each binary compiled.
• In the case of a project that calls a function from a non-system library (e.g.: libft),
your makefile must compile this library automatically.
• All source files you need to compile your project must be explicitly named in your
Makefile.
13