www.delorie.com/djgpp/doc/ug/intro/your-first.html   search  

Guía: Tu Primer Programa

Ya es hora de empezar realmente a hacer algo con djgpp.

Time to actually do something with djgpp!

El tradicional "primer programa" para la gente que aprende C o un nuevo entorno de desarrollo es el clásico "hola mundo". Tiene este aspecto:

The traditional ``first program'' for people learning C or a new development environment is the classic ``hello, world'' program. It looks like this:

#include <stdio.h>

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

Si no conoces C, no esperes que esta Guía te lo enseñe. De todas formas puedes probar djgpp con el programa anterior, y aprender C de un libro escrito para tal propósito.

If you don't know C, don't expect this Guide to teach you. You can still try out djgpp with the above program, and learn C from a book written for that purpose.

Si tienes un editor de texto con el que te sientes a gusto, usalo para escribir el programa anterior. Date cuenta de que no puedes usar un procesador de textos para esto - debes usar uno que guarde el fichero como texto, como por ejemplo notepad o edit. También podrías instalar rhide o emacs y aprender a manejarlos. Si no quieres averiguar nada de eso aún, puedes crear el fichero desde la linea de comandos como se indica a continuación (los ejemplos asumen que tu directorio actual es C:\STUFF):

If you have a text editor you're familiar with, go ahead and type in the above program. Note that you cannot use a word processor for this - you must use something that saves in plain text, like notepad or edit. You could also install and learn to use rhide or emacs. If you don't want to figure any of that out yet, you can still create the file from the command line, like this (the examples assume your current directory is C:\STUFF):

C:\STUFF > copy con hello.c
#include <stdio.h>

int main(void)
{
  printf("Hello, world!\n");
  return 0;
}
<Ctrl-Z>

La última línea significa "presionar la tecla Z mientras mantienes pulsada la tecla CONTROL. Es la forma de DOS de decir "ya está".

That last line means press the Z key while holding the Control key. It's DOS's way of saying ``all done''.

El programa que hace todo el trabajo se llama gcc, que significa GNU C Compiler (Compilador C de GNU). Es un programa front end, que significa que ejecuta otros programas para realizar las distintas tareas que le pides. La línea de comandos que debes teclear en este caso es:

The program that does all the work is called gcc, which stands for GNU C Compiler. It's a front end program, which means that it runs other programs to perform the various tasks you ask of it. The command line you want to type in in this case is thus:

C:\STUFF > gcc hello.c -o hello.exe

Esto le pide al gcc que compile tu código fuente en C y que produzca un ejecutable para DOS. Si funciona, no mostrará ningún mensaje y podrás ejecutar tu programa.

This asks gcc to compile your C source and produce a DOS executable. If it works, it won't print anything, and you'll be able to run your program:

C:\STUFF > hello
Hello, World!

Si sientes curiosidad acerca de como gcc hace su trabajo, o si tienes problemas y necesitas más información acerca de lo que gcc estás intentando hacer, añade -v a la línea de comandos:

If you're curious about how gcc gets its job done, or if you're having problems and you need more information about what gcc is trying to do, add -v to the command line:

C:\STUFF > gcc -v hello.c -o hello.exe

Esto hará que gcc muestre todos los programas que ejecuta, su número de versión, y dónde está buscando cosas.

This will make gcc print out all the programs it runs, its version number, and where it is looking for things.

Traducido por: (10 diciembre 1999)
Revisado por:

  Copyright © 1997   by DJ Delorie     Updated Jan 1997