Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

232
Vistas
How to uglify or minify C code

Using gcc I can remove comments and unwanted blank lines, but I want to reduce a size of file also, is there any options in gcc or any other tool to do so

At present I do like this

gcc -fpreprocessed -dD -E  -P source_code.c > source_code_comments_removed.c 

Here is scenario assume that this is my source_code.c

#include <stdio.h>
main()
{ 
      // declar variable i
      int i=0;

      /* multiline comment
      for loop
      demo stuff
      */
      for(i=1; i<=5; i++)
      {
            // just print something
            printf("Hello %d \n",i);
      }

}

I want to minify like this, removed comments and blank lines

#include <stdio.h>
main(){int i=0;for(i=1; i<=5; i++){printf("Hello %d \n",i);}}

Note : I am on Linux please don't suggest any windows based solution

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

sed -rb 's/ {6}//g' main.c |
sed -rb 's/\/\/.*$//g' |
tr -d '\n' |
sed -rb 's/\/\*.*\*\///g' |
sed -rb 's/(#include.*>)/\1\n/g'

will give you:

#include <stdio.h>
main(){int i=0;for(i=1; i<=5; i++){printf("Hello %d \n",i);}}

However, as stated in the in the comments, this doesn't make much sense and will not reduce the size of your compiled object file!

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda