PpHdLe 18/09/2016 à 21:37
Zeph (./3) :
(pourquoi vous ajoutez tous des "/" à la fin des URLs de yAronet ?)
Fixed
Parce que lorsque j'ai récupéré l'url de suivi-sujets, c'était topics/168363-c-preprocessor-tricks-tips-and-idioms/2#post-59 que j'ai retravaillé trop en supprimant 2#post-59Pas d'idée pour le nom, mais tu as des exemples récents de ce que ça donne à l'utilisation ? 
Quelques exemples:
#include "m-list.h"
#include "m-array.h"
#include "m-dict.h"
#include "m-buffer.h"
#include "m-mutex.h"
LIST_DEF(string, string_t, STRING_OPLIST)
ARRAY_DEF(int, int)
list_string_t current_group;
bool parse_script_command(char buffer[])
{
list_string_t args;
list_it_string_t it;
STRING_DECL_INIT(command);
STRING_DECL_INIT(charac);
STRING_DECL_INIT(effect);
list_string_init (args);
parse_generic_command (args, buffer);
list_string_pop_back (&command, args);
if (string_equal_str_p (command, "JOIN")) {
list_string_pop_back (&charac, args);
list_string_push_back(current_group, charac);
} else if (string_equal_str_p (command, "LEAVE")) {
list_string_pop_back (&charac, args);
for(list_string_begin(it, current_group) ; !list_string_end_p(it) ; list_string_next(it))
if (string_equal_p(charac, *list_string_cref(it)))
list_string_remove (current_group, it);
} else if (string_equal_str_p (command, "GIVE")) {
list_string_pop_back (&charac, args);
list_string_pop_back (&effect, args);
int p = find_character(string_get_cstr(charac));
int w = find_effect(string_get_cstr(effect));
array_int_push_back (character_tab[p].effect_tab, w);
// ...
}
DICT_DEF2(str, string_t, STRING_OPLIST, string_t, STRING_OPLIST)
dict_str_t dict;
void read_dict(void)
{
string_t key, ref;
dict_str_init(dict);
string_init(key);
string_init(ref);
FILE *f = fopen("dict.txt", "rt");
if (!f) abort();
dict_str_set_at(dict, STRING_CTE("LICENCE"), STRING_CTE("BSD3"));
while (!feof(f) && !ferror(f)) {
string_fgets(key, f, STRING_READ_PURE_LINE);
size_t idx = string_search_char(key, ':');
string_set(ref, key);
string_right(ref, idx+1);
string_left(key, idx);
dict_str_set_at (dict, key, ref);
}
fclose(f);
}
void control_dict(void)
{
for EACH(it, dict, DICT_OPLIST(str)) {
const dict_pair_str_t *r = dict_str_cref(it);
printf ("key=%s value=%s\n", string_get_cstr((*r)->key), string_get_cstr((*r)->value));
}
}
// Define a fixed queue of unsigned int
BUFFER_DEF(unsigned int, uint, 10, BUFFER_QUEUE|BUFFER_BLOCKING)
// Define a variable stack of float
BUFFER_DEF(float, floats, 0, BUFFER_STACK|BUFFER_BLOCKING)
// Define a fixed stack of char without blocking
BUFFER_DEF(char, char, 10, BUFFER_STACK|BUFFER_UNBLOCKING)
// Define a fixed queue of long long, unthread safe and without blocking
BUFFER_DEF(long long, llong, 16, BUFFER_QUEUE|BUFFER_THREAD_UNSAFE|BUFFER_UNBLOCKING)
// Define a fixed queue of mpz_t
#include <gmp.h>
BUFFER_DEF(mpz_t, mpz, 32, BUFFER_QUEUE, (INIT(mpz_init), SET(mpz_set), CLEAR(mpz_clear)))
buffer_uint_t g_buff;
static void *conso(void *arg)
{
unsigned int j;
assert (arg == NULL);
for(int i = 0; i < 1000;i++) {
buffer_uint_pop(&j, g_buff);
assert (j < 1000);
}
return NULL;
}
static void *prod(void *arg)
{
assert (arg == NULL);
for(unsigned int i = 0; i < 1000;i++)
buffer_uint_push(g_buff, &i);
return NULL;
}
static void test_global(void)
{
M_THREAD_T idx_p[100];
M_THREAD_T idx_c[100];
buffer_uint_init(g_buff, 10);
for(int i = 0; i < 100; i++) {
M_THREAD_CREATE (idx_p[i], conso, NULL);
M_THREAD_CREATE (idx_c[i], prod, NULL);
}
for(int i = 0; i < 100;i++) {
M_THREAD_JOIN(idx_p[i]);
M_THREAD_JOIN(idx_c[i]);
}
buffer_uint_clear(g_buff);
}