Está en la página 1de 13

UNIVERSIDAD DE LAS FUERZAS ARMADAS

– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN

GUÍA PARA LAS PRÁCTICAS DE LABORATORIO, TALLER O CAMPO


PERIODO
ASIGNATURA: Sistemas Operativos 201951 NIVEL: 3ro
LECTIVO:
DOCENTE: Rolando Armas, PhD. NRC: 4847(A) / 4849 (B) PRÁCTICA N°: 4
LABORATORIO DONDE SE DESARROLLARÁ LA
Laboratorio de Computación Nº. 4
PRÁCTICA:
TEMA DE LA
PRÁCTICA: Unidad 02-Laboratorio 4: Introducción a GNU C
INTRODUCCIÓN:

El compilador original GNU C (GCC) fue desarrollado por Richard Stallman, el fundador del Proyecto GNU. Richard Stallman fundó
el proyecto GNU en 1984 para crear un sistema operativo completo similar a Unix como software libre, para promover la libertad y
la cooperación entre los usuarios de computadoras y los programadores.

GCC, anteriormente para "GNU C Compiler", ha crecido con el tiempo para admitir muchos lenguajes como C (gcc), C ++ (g ++),
Objective-C, Objective-C ++, Java (gcj), Fortran (gfortran), Ada ( gnat), Go (gccgo), OpenMP, Cilk Plus y OpenAcc. Ahora se
conoce como "Colección del compilador GNU". El sitio para GCC es http://gcc.gnu.org/. La versión actual es GCC 7.3, lanzada el
25-01-2018.

OBJETIVOS:

Familiarizarse con el entorno de GNU C en Linux


Revisar algunos fundamentos de C
MATERIALES:

INSUMOS: Sistemas Operativo Linux


REACTIVOS: N/A gcc

EQUIPOS: Computador de escritorio del Laboratorio de Computación

MUESTRA:
INSTRUCCIONES:
Chequear la versión de gcc:
a) $ gcc --version
b) $ g++ --version

Obtener información de ayuda


c) $ gcc --help
d) $ man gcc
UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN

Mas informacion sobre gcc


e) gcc -v
f) g++ -v

Compilar un simple programa en C

// hello.c
#include <stdio.h>

int main() {
printf("Hello, world!\n");
return 0;
}

Compilar:
g) $ gcc Hello.c
h) Por defecto el nombre del ejecutable es a.out

Ejecutar el programa
i) Asignar permisos: $ chmod +x a.out
j) Ejecutar el programa: $ ./a.out

Más opciones de compilación de gcc:


k) g++ -Wall -g -o Hello.bin Hello.c
i) -Wall imprime todos los mensajes de error (Warnings)
ii) -o especifica el nombre del ejecutable
iii) -g genera información sobre depuración

Modo Verbose:
l) gcc -v -o Hello.bin Hello.c
i) Ver el proceso detallado de la compilación
Compilar el siguiente programa:

#include <stdio.h>

int main() {
int count;
puts("Please enter a number: ");
scanf("%d", &count);
printf("The number is %d \n", count);
}
UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN

Revisión de algunos fundamentos de C.


Escriba los siguientes programas en C. Compilar con GCC y ejecutarlos dentro del entorno Linux.

Variables: Valores máximos de las variables numéricas

#include <stdio.h>
#include <float.h>
#include <limits.h>

int main()
{
unsigned long long ullmax = ULLONG_MAX;
long lmax = LONG_MAX;
long double ldmax = LDBL_MAX;

printf("The max value of an unsigned long long is %Lu.\n", ullmax);


printf("The max value of a long is %ld.\n", lmax);
printf("The max value of a long double is %Lf.\n", ldmax);

return 0;

Referencias:
GCC and Make Compiling, Linking and Building C/C++ Applications
https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html

An Overview of Compiling and Linking


https://dn.embarcadero.com/article/29930

https://linuxconfig.org/c-development-on-linux-flow-control-iv
ACTIVIDADES POR DESARROLLAR:
1) Compile y Ejecute las siguientes rutinas
a) Control de Flujo:

#include <stdio.h>
UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN

int main()
{
char option;
int number;

printf("Please enter the number you want converted.\n");


/*Please refrain from using gets() because of its
* insecure "features" */
scanf("%i", &number);

printf("What kind of conversion do you need?\n");


printf("Press 'o' for octal and 'x' for hexadecimal.\n");

while((option = getchar()) != EOF && (option = getchar()) != '\n')


{
switch(option)
{
case 'o':
printf("The number in octal is 0%o.\n", number);
break;
case 'x':
printf("The number in hex is 0x%x.\n", number);
break;
default:
printf("Option not valid.\n");
break;
}
}
return 0;

b) Funciones:
¿Cómo implementar una función para calcular el factorial de un número?

#include <stdio.h>

/* Factorial */

int factorial(int number)


UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN

if(number <= 1)

return 1;

else

return number * factorial(number-1);

int main()

int numF=1;

long numFR=0; //factorial de numF

printf("Por favor ingrese el numero entero que desea calcular el


factorial\n");

scanf("%i",&numF);

numFR=factorial(numF);

printf("El resultado del factorial %ld\n", numFR);

return 0;

c) Punteros y Arreglos: Revise el siguiente código, compilar con gcc y ejecutarlo

#include <stdio.h>
UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN

#include <string.h>

int main()
{
char stringy[30];
int i;
char c;
printf("Type a string .\n");
fgets(stringy, 30, stdin);
printf("\n");

for(i = 0; i < strlen(stringy); i++)


printf("%c", stringy[i]);
printf("\n");
for(i = strlen(stringy); i >= 0; i--)
printf("%c", stringy[i]);
printf("\n");

return 0;
}

2) Compilar y generar un ejecutable con GCC en linux de un programa en C/C++ de al menos de 50 líneas
desarrollado en cursos previos.
a) Mostrar el código fuente en el reporte
b) Mostrar los resultados de la compilación
c) Mostrar los resultados de la ejecución.
RESULTADOS OBTENIDOS:

Chequear la versión de gcc:


· $ gcc --version

· $ g++ --version

Obtener información de ayuda


· $ gcc –help
UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN

·
· $ man gcc

$ gcc –v
UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN

$ g++ -v
UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN
UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN

ACTIVIDADES POR DESARROLLAR:

1) Compile y Ejecute las siguientes rutinas


a) Control de Flujo
UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN
UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN

CONCLUSIONES:

 Linux nos permite ejecutar programa en c mediante su editor, que permite ejecutar
programa realizado en c y su a vez editarlo dentro del entorno.
 Se ejecutaron los scripts correctamente mediante el comando chmod +x que da
permiso de ejecución.
 Mediante el comando gcc y el nombre del archivo hace que utilice el compilador de c,
ya que Linux tiene varios compiladores.

RECOMENDACIONES:

 Se recomienda que para poder ejecutar el programa debemos ejecutar el compilador, en


este caso el compilador de c es gcc.
 En el segundo paso para ejecutar se recomienda usar el comando de permiso de
ejecución chmod +x.
 Es importante guardar el archivo con el nombrearchivo.c para que sepa que el script usa
el lenguaje de c.
FIRMAS
UNIVERSIDAD DE LAS FUERZAS ARMADAS
– ESPE CÓDIGO:
SGC.DI.505
VERSIÓN: 1.0
DEPARTAMENTO DE CIENCIAS DE LA FECHA ÚLTIMA
COMPUTACIÓN REVISIÓN:
26/10/16

CARRERA: INGENIERÍA EN TECNOLOGÍAS DE LA


INFORMACIÓN

F:………………………………………….
Nombre: F: …………………………………………. F: ……………………………………………..
Nombre: Nombre:
Rolando Armas, PhD COORDINADOR DE ÁREA DE COORDINADOR DE LABORATORIOS
CONOCIMIENTO

También podría gustarte