[sprintf] Use 'restrict' pointers ?

Aperta
#22 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
55/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
c
Ambito
tooling

Direzione di ricerca

The change touches the public vsprintf, vsnprintf, sprintf, snprintf and vsprintfcb declarations in the single header stb_sprintf.h, plus a STBSP__RESTRICT macro that would be defined conditionally on __STDC_VERSION__. Start by reading those declarations and checking how the header is compiled in its own test or build setup. Done means the signatures carry the qualifier under C99 and compile unchanged elsewhere; the thread has no maintainer decision yet, so confirm the direction before editing.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

In the standard printf functions, the output buffer and the format string are declared as 'restrict' pointers (char restrict, const char* restrict).
This was introduced in C99, at least according to https://en.cppreference.com/w/c/io/fprintf
It does not exist in C++

The function signatures could be changed in this way:

STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsprintf)(char * STBSP__RESTRICT buf, char const * STBSP__RESTRICT fmt, va_list va);
STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsnprintf)(char * STBSP__RESTRICT buf, int count, char const * STBSP__RESTRICT fmt, va_list va);
STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(sprintf)(char * STBSP__RESTRICT buf, char const * STBSP__RESTRICT fmt, ...) STBSP__ATTRIBUTE_FORMAT(2,3);
STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(snprintf)(char * STBSP__RESTRICT buf, int count, char const * STBSP__RESTRICT fmt, ...) STBSP__ATTRIBUTE_FORMAT(3,4);
STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, void *user, char * STBSP__RESTRICT buf, char const * STBSP__RESTRICT fmt, va_list va);

with:

#if defined(__STDC_VERSION__) && (__STDC_VERSION__) >= 199901L
   #define STBSP__RESTRICT    restrict
#else
   #define STBSP__RESTRICT
#endif

Restrict pointers might help the compiler optimize access to those arrays.

Lingua principale
C
Stelle
18
Fork
5
Merge medio
1m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nothings/stb_sprintf

Tutte le issue di nothings/stb_sprintf

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.