Editando
C5 - Introducción a C
(sección)
Ir a la navegación
Ir a la búsqueda
Advertencia:
no has iniciado sesión. Tu dirección IP se hará pública si haces cualquier edición. Si
inicias sesión
o
creas una cuenta
, tus ediciones se atribuirán a tu nombre de usuario, además de otros beneficios.
Comprobación antispam. ¡
No
rellenes esto!
= C5.2 Structure Organitzacion = <br> *Cuando escribimos un programa es conveniente hacerlo de forma ordenada *Se pueden incluir a modo de comentario las diferentes secciones con las que cuenta un programa <br> Hay 4 secciones importantes en todo programa: *Documentacion **Proposito del software **Autores **Fecha **Informacion copyright **Si hay hardware externo se explica como esta conectado *Directivas de pre-proceso **Se ponen los #includes *Declaracion de variables globales **Se declaran las variables globales y las "function prototypes" *Subrutinas **Las funciones que desarollamos **La función principal que es el main <br> Ejemplo:<br> <br> //**** 0. Documentation Section // This program calculates the area of square shaped rooms // Author: Ramesh Yerraballi & Jon Valvano // Date: 6/28/2013 // // 1. Pre-processor Directives Section #include <stdio.h> // Diamond braces for sys lib: Standard I/O #include "uart.h" // Quotes for user lib: UART lib unsigned long calcArea(unsigned long a); // 2. Global Declarations section unsigned long side; // 3. Subroutines Section // MAIN: Mandatory routine for a C program to be executable int main(void) { unsigned long area; UART_Init(); // call subroutine to initialize the uart printf("This program calculates areas of square-shaped rooms\n"); side=3; area = calcArea(side); printf("The area of room is: %",area); } unsigned long calcArea(unsigned long a){ unsigned long area; area = a * a; return area; } <br> En este código se puede ver las diferentes partes de las que se han hablado <br> Secciones código: *Descripción del programa *Autores *Fecha *Includes *main <br> There are four sections of a C program as shown in Program 5.2. The first section is the documentation section, which includes the purpose of the software, the authors, the date, and any copyright information. When the software involves external hardware we will add information about how the external hardware is connected. The second section is the preprocessor directives. We will use the preprocessor directive #include to connect this software with other modules. We use diamond braces to include system libraries, like the standard I/O, and we use quotes to link up with other user code within the project. In this case the uart module is software we wrote to perform I/O with the universal asynchronous receiver/transmitter (uart). We will discuss modular programming in great detail in this class. The third section is global declarations section. This section will include global variables and function prototypes for functions defined in this module. The last section will be the functions themselves. In this class we will use the terms subroutine, procedure, function, and program interchangeably. Every software system in C has exactly one main program, which defines where it begins execution. <br> <br> There are two types of comments. The first type explains how to use the software. These comments are usually placed at the top of the file, within the header file, or at the start of a function. The reader of these comments will be writing software that uses or calls these routines. The second type of comments assists a future programmer (ourselves included) in changing, debugging or extending these routines. We usually place these comments within the body of the functions. The comments on the right of each line are examples of the second type. <br> <br>
Resumen:
Ten en cuenta que todas las contribuciones a Proyectos se consideran publicadas bajo la Creative Commons Atribución-CompartirIgual (véase
Proyectos:Derechos de autor
para más información). Si no deseas que las modifiquen sin limitaciones y las distribuyan libremente, no las publiques aquí.
Al mismo tiempo, asumimos que eres el autor de lo que escribiste, o lo copiaste de una fuente en el dominio público o con licencia libre.
¡No uses textos con copyright sin permiso!
Cancelar
Ayuda de edición
(se abre en una ventana nueva)
Menú de navegación
Herramientas personales
No has accedido
Discusión
Contribuciones
Crear una cuenta
Acceder
Espacios de nombres
Página
Discusión
español
Vistas
Leer
Editar
Ver historial
Más
Buscar
Navegación
Página principal
Cambios recientes
Página aleatoria
Ayuda sobre MediaWiki
Páginas especiales
Herramientas
Lo que enlaza aquí
Cambios relacionados
Información de la página