Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple instructions in return #497

Open
Qpupier opened this issue Jun 10, 2024 · 1 comment
Open

Multiple instructions in return #497

Qpupier opened this issue Jun 10, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Qpupier
Copy link

Qpupier commented Jun 10, 2024

Description
Multiple instructions in a return don't make an error

Exemple

/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   test.c                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: Kunfandi <[email protected]>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2024/06/10 17:15:35 by Kunfandi          #+#    #+#             */
/*   Updated: 2024/06/10 17:17:20 by Kunfandi         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <stdio.h>

int	main(void)
{
	return (printf("OK\n"), 0);
}

This file is good with the norminette but it shouldn't.

Additional infos
norminette 3.3.55

@Asandolo Asandolo added the bug Something isn't working label Jun 21, 2024
@BWG31
Copy link

BWG31 commented Sep 12, 2024

I'd be very curious to know an official opinion on the matter.

The norm (v4) III.2 (Formatting) states: "One instruction per line."
I think the use of the word "instruction" is confusion and perhaps should be "statement"?

return(function_call(), 0); This is one statement (return) containing two expressions.

if (ft_isprint(c) && ft_isdigit(c)) This is also one statement (if) containing two expressions.

if (ft_isprint(c), ft_isdigit(c)) Same again (silly but norm friendly).

My thoughts:

  • If you only allowed one expression per line there would be riots.
  • It is still mostly conducive to clean code thanks to the other rules: "One single variable declaration per line" & "Multiple assignments are strictly forbidden."
  • You could 'abuse' this by stacking lots of comma-seperated expressions in a return (or other) statement but I'd like to think that by doing so your evaluators would encourage you to do better.
  • Once you wrap your head around the comma operator return (printf("OK\n"), 0); isn't too bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants