| Ver tema anterior :: Ver siguiente tema | | Autor | Mensaje |
|---|
jacintolucas
Registrado: 06 Mar 2014 Mensajes: 5
| Publicado: 14/05/2014 9:54 am | | | Título: hilos |
| Hola, buenas tardes.
Tengo una duda, ¿cuál de estas dos formas es la correcta para crear un hilo?
pthread_create(&thread1, NULL, &rutina1, NULL);
ó
pthread_create(&thread1, NULL, rutina1, NULL);
donde rutina1:
void *rutina1(void *arg) { ... } |
| | Volver arriba | |  | rir3760

Registrado: 01 Oct 2004 Mensajes: 7516 Ubicación: Mexico
| Publicado: 14/05/2014 5:44 pm | | | Título: |
| Ambas son validas.
En el primer caso al utilizar "&rutina1" el resultado es un puntero a función, en el segundo el identificador de la función genera de forma automática el puntero necesario.
Como el resultado es el mismo se prefiere la forma mas corta: simplemente utilizar el nombre.
Un ejemplo para explicarlo mejor:
| Código: | #include <stdio.h> #include <stdlib.h>
int main(void) { int (*p)(char const *); p = puts; p("hola, mundo"); p = &puts; p("adios, mundo cruel"); return EXIT_SUCCESS; } |
Un saludo _________________ C retains the basic philosophy that programmers know what they are doing; it only requires that they state their intentions explicitly. -- Kernighan & Ritchie, The C programming language |
| | Volver arriba | |  | | |
| No puede crear mensajes No puede responder temas No puede editar sus mensajes No puede borrar sus mensajes No puede votar en encuestas
|
|
| |