8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

clang-formatのstyle比較

Posted at

ひどいコードがclang-formatでどのように整形されるか,styleごとに見てみる.

汚いコード
/*
  test comment
        */

#include<stdio.h>
#include<stdlib.h>

int add(const int *a, int n)
{int b=0;
for (int i = 0; i < n; i++) b += a[i];
  { int c=b; /* who knows? */ }
return b;}

int main( ){
  int i,n=5; // numbers
int data[n]; /* array */
  int *p = data; // what ?
for(i=0;i<n;i++)
  {
data[i]=i;
  } 
  add(data,n);  return 0;
}

LLVM

-style=LLVM
/*
  test comment
        */

#include <stdio.h>
#include <stdlib.h>

int add(const int *a, int n) {
  int b = 0;
  for (int i = 0; i < n; i++)
    b += a[i];
  { int c = b; /* who knows? */ }
  return b;
}

int main() {
  int i, n = 5;  // numbers
  int data[n];   /* array */
  int *p = data; // what ?
  for (i = 0; i < n; i++) {
    data[i] = i;
  }
  add(data, n);
  return 0;
}

Google

-style=Google
/*
  test comment
        */

#include <stdio.h>
#include <stdlib.h>

int add(const int *a, int n) {
  int b = 0;
  for (int i = 0; i < n; i++) b += a[i];
  { int c = b; /* who knows? */ }
  return b;
}

int main() {
  int i, n = 5;   // numbers
  int data[n];    /* array */
  int *p = data;  // what ?
  for (i = 0; i < n; i++) {
    data[i] = i;
  }
  add(data, n);
  return 0;
}

Chromium

-style=Chromium
/*
  test comment
        */

#include <stdio.h>
#include <stdlib.h>

int add(const int* a, int n) {
  int b = 0;
  for (int i = 0; i < n; i++)
    b += a[i];
  { int c = b; /* who knows? */ }
  return b;
}

int main() {
  int i, n = 5;   // numbers
  int data[n];    /* array */
  int* p = data;  // what ?
  for (i = 0; i < n; i++) {
    data[i] = i;
  }
  add(data, n);
  return 0;
}

Mozilla

-style=Mozilla
/*
  test comment
        */

#include <stdio.h>
#include <stdlib.h>

int add(const int *a, int n) {
  int b = 0;
  for (int i = 0; i < n; i++)
    b += a[i];
  { int c = b; /* who knows? */ }
  return b;
}

int main() {
  int i, n = 5;  // numbers
  int data[n];   /* array */
  int *p = data; // what ?
  for (i = 0; i < n; i++) {
    data[i] = i;
  }
  add(data, n);
  return 0;
}

WebKit

-style=WebKit
/*
  test comment
        */

#include <stdio.h>
#include <stdlib.h>

int add(const int* a, int n)
{
    int b = 0;
    for (int i = 0; i < n; i++)
        b += a[i];
    {
        int c = b; /* who knows? */
    }
    return b;
}

int main()
{
    int i, n = 5; // numbers
    int data[n]; /* array */
    int* p = data; // what ?
    for (i = 0; i < n; i++) {
        data[i] = i;
    }
    add(data, n);
    return 0;
}
8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?