r3 - 25 Aug 2005 - 14:31:13 - IuriDinizYou are here: TWiki >  Personal Web  > LinguagemC

Compiladores

gcc extensions: http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html

Macros e Pré-processador

Símbolo ##

Concatena dois argumentos

exemplo:

#define irado(a,b) a ## b 

int main() {
   int ab;
   int g;
   g = irado(a,b);
   return 0;
}
Após o Pré-processador agir fica:
int main() {
   int ab;
   int g;
   g = ab;
   return 0;
}
-- IuriDiniz - 03 Jul 2005

Símbolo #

Coloca o argumento entre "" (áspas)

exemplo:

#define string(x) #x

int main() {
    char *nome = string(Iuri Gomes Diniz);
}
Após o Pré-processador agir fica:
int main() {
    char *nome = "Iuri Gomes Diniz";
}

Posix Threads (pthread)

#include <pthread.h>
#include <stdbool.h>

pthread_mutex_t mutex_flip = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_flip = PTHREAD_COND_INITIALIZER;
bool flip=false;

static inline void do_flip() {
  primary->Flip(primary, NULL, 0);
}

void directfb_setneedflip() {
  pthread_mutex_lock(&mutex_flip);
  flip = true;
  /* signal a thread that is waiting for cond_flip */
  pthread_cond_signal(&cond_flip);
  pthread_mutex_unlock(&mutex_flip);
  
}

static void* daemon_flip(void* p) {
  while (1) {
    pthread_mutex_lock(&mutex_flip);
    /* Sleep until flip becomes true. */
    while (flip == false) {
      pthread_cond_wait(&cond_flip, &mutex_flip);
    }
    do_flip();
    flip = false;
    pthread_mutex_unlock(&mutex_flip);
  }
  
}

-- IuriDiniz - 03 Jul 2005

-- IuriDiniz - 15 Jul 2005

-- IuriDiniz - 25 Aug 2005

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r3 < r2 < r1 | More topic actions
Personal.LinguagemC moved from Personal.LinguagemProgramacaoC on 25 Aug 2005 - 14:29 by IuriDiniz - put it back
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback