Add a helper function `voidp` to silence GCC warnings about `%p`.

We must fully qualify calls to `hr::voidp` because the expression
`voidp(x)` is ambiguous or worse. "/usr/include/zconf.h" defines
`voidp` in the global namespace as a typedef for `void*`.
We don't want an unsafe functional-style cast to `void*`;
we want to call our nice safe helper function. So we qualify the name.
This commit is contained in:
Arthur O'Dwyer 2020-02-22 21:48:46 -05:00
parent 13bf666e29
commit 7a706478dc
10 changed files with 53 additions and 48 deletions

View File

@ -557,7 +557,7 @@ struct hrmap_archimedean : hrmap {
heptagon *create_step(heptagon *h, int d) override {
DEBB(DF_GEOM, (format("%p.%d ~ ?\n", h, d)));
DEBB(DF_GEOM, (format("%p.%d ~ ?\n", hr::voidp(h), d)));
heptspin hi(h, d);
@ -707,7 +707,7 @@ EX hrmap *new_map() { return new hrmap_archimedean; }
heptagon *build_child(heptspin p, pair<int, int> adj) {
indenter ind;
auto h = buildHeptagon1(tailored_alloc<heptagon> (isize(current.adjacent[adj.first])), p.at, p.spin, hstate(1), 0);
DEBB(DF_GEOM, (format("NEW %p.%d ~ %p.0\n", p.at, p.spin, h)));
DEBB(DF_GEOM, (format("NEW %p.%d ~ %p.0\n", hr::voidp(p.at), p.spin, hr::voidp(h))));
id_of(h) = adj.first;
parent_index_of(h) = adj.second;
int nei = neighbors_of(h);
@ -751,13 +751,13 @@ void connect_digons_too(heptspin h1, heptspin h2) {
// no need to specify archimedean_gmatrix and altmap
hnew->c.connect(1, h2);
h1--, h2++;
DEBB(DF_GEOM, (format("OL2 %p.%d ~ %p.%d\n", h1.at, h1.spin, h2.at, h2.spin)));
DEBB(DF_GEOM, (format("OL2 %p.%d ~ %p.%d\n", hr::voidp(h1.at), h1.spin, hr::voidp(h2.at), h2.spin)));
h1.at->c.connect(h1.spin, h2);
}
}
void connectHeptagons(heptspin hi, heptspin hs) {
DEBB(DF_GEOM, (format("OLD %p.%d ~ %p.%d\n", hi.at, hi.spin, hs.at, hs.spin)));
DEBB(DF_GEOM, (format("OLD %p.%d ~ %p.%d\n", hr::voidp(hi.at), hi.spin, hr::voidp(hs.at), hs.spin)));
if(hi.at->move(hi.spin) == hs.at && hi.at->c.spin(hi.spin) == hs.spin) {
DEBB(DF_GEOM, (format("WARNING: already connected\n")));
return;

View File

@ -43,7 +43,7 @@ EX void preventbarriers(cell *c) {
}
EX bool checkBarriersBack(cellwalker bb, int q IS(5), bool cross IS(false)) {
// printf("back, %p, s%d\n", bb.at, bb.spin);
// printf("back, %p, s%d\n", hr::voidp(bb.at), bb.spin);
// if(mark) { printf("mpdist = %d [%d] bardir = %d spin=%d q=%d cross=%d\n", bb.at->mpdist, BARLEV, bb.at->bardir, bb.spin, q, cross); }
@ -172,7 +172,7 @@ EX bool mirrorwall(cell *c) {
}
EX void extendBarrierFront(cell *c) {
limitgen("extend front %p\n", c);
limitgen("extend front %p\n", hr::voidp(c));
if(buggyGeneration) return;
int ht = c->landparam;
extendcheck(c);
@ -222,7 +222,7 @@ EX void extendBarrierFront(cell *c) {
}
EX void extendBarrierBack(cell *c) {
limitgen("extend back %p\n", c);
limitgen("extend back %p\n", hr::voidp(c));
if(buggyGeneration) return;
int ht = c->landparam;
extendcheck(c);
@ -343,14 +343,14 @@ EX bool isbar4(cell *c) {
}
EX void extendBarrier(cell *c) {
limitgen("extend barrier %p\n", c);
limitgen("extend barrier %p\n", hr::voidp(c));
if(buggyGeneration) return;
if(c->barleft == NOWALLSEP_USED) return;
extendcheck(c);
// printf("build barrier at %p", c);
// printf("build barrier at %p", hr::voidp(c));
if(c->land == laBarrier || c->land == laElementalWall || c->land == laHauntedWall || c->land == laOceanWall ||
c->land == laMirrorWall || c->land == laMirrorWall2 || c->land == laMercuryRiver) {
// printf("-> ready\n");
@ -456,7 +456,7 @@ EX void buildBarrier(cell *c, int d, eLand l IS(laNone)) {
}
EX bool buildBarrier6(cellwalker cw, int type) {
limitgen("build6 %p/%d (%d)\n", cw.at, cw.spin, type);
limitgen("build6 %p/%d (%d)\n", hr::voidp(cw.at), cw.spin, type);
cellwalker b[4];
@ -481,7 +481,7 @@ EX bool buildBarrier6(cellwalker cw, int type) {
if(false) {
for(int z=0; z<4; z++) {
printf("%p/%d\n", b[z].at, b[z].spin);
printf("%p/%d\n", hr::voidp(b[z].at), b[z].spin);
b[z].at->wall = waStrandedBoat; b[z].at->land = laAlchemist;
b[z].at->mondir = b[z].spin;
b[z].at->mpdist = 7;
@ -567,7 +567,7 @@ EX bool buildBarrier6(cellwalker cw, int type) {
}
EX bool buildBarrier4(cell *c, int d, int mode, eLand ll, eLand lr) {
limitgen("build4 %p\n", c);
limitgen("build4 %p\n", hr::voidp(c));
if(buggyGeneration) return true;
d %= 7;
@ -833,7 +833,7 @@ EX bool buildBarrierNowall(cell *c, eLand l2, int forced_dir IS(NODIR)) {
#endif
if(c->land == laNone) {
printf("barrier nowall! [%p]\n", c);
printf("barrier nowall! [%p]\n", hr::voidp(c));
raiseBuggyGeneration(c, "barrier nowall!");
return false;
}

View File

@ -168,10 +168,10 @@ void hrmap::generateAlts(heptagon *h, int levs, bool link_cdata) {
}
if(relspin == -4 && geometry != gFieldQuotient) {
if(h->alt != h->alt->alt) {
printf("relspin {%p:%p}\n", h->alt, h->alt->alt);
{for(int i=0; i<S7; i++) printf("%p ", h->alt->move(i));} printf(" ALT\n");
{for(int i=0; i<S7; i++) printf("%p ", h->move(i));} printf(" REAL\n");
{for(int i=0; i<S7; i++) printf("%p ", h->move(i)->alt);} printf(" REAL ALT\n");
printf("relspin {%p:%p}\n", hr::voidp(h->alt), hr::voidp(h->alt->alt));
{for(int i=0; i<S7; i++) printf("%p ", hr::voidp(h->alt->move(i)));} printf(" ALT\n");
{for(int i=0; i<S7; i++) printf("%p ", hr::voidp(h->move(i)));} printf(" REAL\n");
{for(int i=0; i<S7; i++) printf("%p ", hr::voidp(h->move(i)->alt));} printf(" REAL ALT\n");
}
relspin = 3;
} }
@ -183,8 +183,8 @@ void hrmap::generateAlts(heptagon *h, int levs, bool link_cdata) {
heptagon *hm = h->alt->move(ir);
heptagon *ho = createStep(h, i);
// printf("[%p:%d ~ %p:%d] %p ~ %p\n",
// h, i, h->alt, ir,
// ho, hm);
// hr::voidp(h), i, hr::voidp(h->alt), ir,
// hr::voidp(ho), hr::voidp(hm));
if(ho->alt && ho->alt != hm) {
if(ho->alt->alt == hm->alt && !quotient) {
printf("ERROR: alt cross! [%d -> %d]\n", ho->alt->distance, hm->distance);
@ -287,7 +287,7 @@ EX heptagon *createAlternateMap(cell *c, int rad, hstate firststate, int special
heptagon *alt = tailored_alloc<heptagon> (h->type);
allmaps.push_back(newAltMap(alt));
//printf("new alt {%p}\n", alt);
//printf("new alt {%p}\n", hr::voidp(alt));
alt->s = firststate;
alt->emeraldval = 0;
alt->zebraval = 0;
@ -328,7 +328,7 @@ EX heptagon *createAlternateMap(cell *c, int rad, hstate firststate, int special
}
return alt;
//for(int d=rad; d>=0; d--) printf("%3d. %p {%d}\n", d, cx[d]->master, cx[d]->master->alt->distance);
//for(int d=rad; d>=0; d--) printf("%3d. %p {%d}\n", d, hr::voidp(cx[d]->master), cx[d]->master->alt->distance);
}
EX void beCIsland(cell *c) {
@ -393,7 +393,7 @@ EX void generateTreasureIsland(cell *c) {
if(cc->wall != waCTree)
end = false;
}
// printf("%p: end=%d, qc=%d, dist=%d\n", c, end, qc, celldistAlt(c));
// printf("%p: end=%d, qc=%d, dist=%d\n", hr::voidp(c), end, qc, celldistAlt(c));
if(end) c->item = itPirate;
else c->item = itCompass;
}
@ -567,7 +567,7 @@ EX void buildEquidistant(cell *c) {
eLand b = c->land;
if(chaosmode && !inmirror(b)) return;
if(!b) {
printf("land missing at %p\n", c);
printf("land missing at %p\n", hr::voidp(c));
describeCell(c);
for(int i=0; i<c->type; i++) if(c->move(i))
describeCell(c->move(i));

View File

@ -85,7 +85,7 @@ struct hrmap_hyperbolic : hrmap_standard {
heptagon *getOrigin() override { return origin; }
~hrmap_hyperbolic() {
// verifycells(origin);
// printf("Deleting hyperbolic map: %p\n", this);
// printf("Deleting hyperbolic map: %p\n", hr::voidp(this));
clearfrom(origin);
}
void verify() override { verifycells(origin); }
@ -203,7 +203,7 @@ EX cell *createMov(cell *c, int d) {
else if(GOLDBERG) {
gp::extend_map(c, d);
if(!c->move(d)) {
printf("extend failed to create for %p/%d\n", c, d);
printf("extend failed to create for %p/%d\n", hr::voidp(c), d);
exit(1);
}
hybrid::link();
@ -314,9 +314,9 @@ EX void initcells() {
EX void clearcell(cell *c) {
if(!c) return;
DEBB(DF_MEMORY, (format("c%d %p\n", c->type, c)));
DEBB(DF_MEMORY, (format("c%d %p\n", c->type, hr::voidp(c))));
for(int t=0; t<c->type; t++) if(c->move(t)) {
DEBB(DF_MEMORY, (format("mov %p [%p] S%d\n", c->move(t), c->move(t)->move(c->c.spin(t)), c->c.spin(t))));
DEBB(DF_MEMORY, (format("mov %p [%p] S%d\n", hr::voidp(c->move(t)), hr::voidp(c->move(t)->move(c->c.spin(t))), c->c.spin(t))));
if(c->move(t)->move(c->c.spin(t)) != NULL &&
c->move(t)->move(c->c.spin(t)) != c) {
DEBB(DF_MEMORY | DF_ERROR, (format("cell error: type = %d %d -> %d\n", c->type, t, c->c.spin(t))));
@ -324,7 +324,7 @@ EX void clearcell(cell *c) {
}
c->move(t)->move(c->c.spin(t)) = NULL;
}
DEBB(DF_MEMORY, (format("DEL %p\n", c)));
DEBB(DF_MEMORY, (format("DEL %p\n", hr::voidp(c))));
tailored_delete(c);
}
@ -416,7 +416,7 @@ EX void verifycell(cell *c) {
if(c2) {
if(BITRUNCATED && c == c->master->c7) verifycell(c2);
if(c2->move(c->c.spin(i)) && c2->move(c->c.spin(i)) != c) {
printf("cell error %p:%d [%d] %p:%d [%d]\n", c, i, c->type, c2, c->c.spin(i), c2->type);
printf("cell error %p:%d [%d] %p:%d [%d]\n", hr::voidp(c), i, c->type, hr::voidp(c2), c->c.spin(i), c2->type);
exit(1);
}
}
@ -426,7 +426,7 @@ EX void verifycell(cell *c) {
EX void verifycells(heptagon *at) {
if(GOLDBERG || IRREGULAR || arcm::in()) return;
for(int i=0; i<at->type; i++) if(at->move(i) && at->move(i)->move(at->c.spin(i)) && at->move(i)->move(at->c.spin(i)) != at) {
printf("hexmix error %p [%d s=%d] %p %p\n", at, i, at->c.spin(i), at->move(i), at->move(i)->move(at->c.spin(i)));
printf("hexmix error %p [%d s=%d] %p %p\n", hr::voidp(at), i, at->c.spin(i), hr::voidp(at->move(i)), hr::voidp(at->move(i)->move(at->c.spin(i))));
}
if(!sphere && !quotient)
for(int i=0; i<S7; i++) if(at->move(i) && at->c.spin(i) == 0 && at->s != hsOrigin)

View File

@ -2629,7 +2629,7 @@ EX namespace dragon {
}
if(cmode & sm::MAP) return c;
if(!history::includeHistory) {
printf("dragon bug #3 (%p -> %p)\n", cor, c);
printf("dragon bug #3 (%p -> %p)\n", hr::voidp(cor), hr::voidp(c));
dragbugs = true;
}
c->monst = moDragonHead; return c;
@ -3119,7 +3119,7 @@ EX namespace prairie {
forCellEx(c2, c) forCellEx(c3, c2)
if(barrierhept(c3)) barclose++;
printf("c = %p bc = %d\n", c, barclose);
printf("c = %p bc = %d\n", hr::voidp(c), barclose);
raiseBuggyGeneration(c, "could not set river fval");
}

View File

@ -44,7 +44,7 @@ bool errorReported = false;
EX void describeCell(cell *c) {
if(!c) { printf("NULL\n"); return; }
printf("describe %p: ", c);
printf("describe %p: ", hr::voidp(c));
printf("%-15s", linf[c->land].name);
printf("%-15s", winf[c->wall].name);
printf("%-15s", iinf[c->item].name);
@ -285,7 +285,7 @@ EX bool applyCheat(char u, cell *c IS(NULL)) {
if(u == 'L'-64) {
cell *c = mouseover;
describeCell(c);
printf("Neighbors:"); for(int i=0; i<c->type; i++) printf("%p ", c->move(i));
printf("Neighbors:"); for(int i=0; i<c->type; i++) printf("%p ", hr::voidp(c->move(i)));
printf("Barrier: dir=%d left=%d right=%d\n",
c->bardir, c->barleft, c->barright);
return true;
@ -358,7 +358,7 @@ struct debugScreen {
queuepoly(gmatrix[what], cgi.shAsymmetric, 0x80808080);
#endif
char buf[200];
sprintf(buf, "%p", what);
sprintf(buf, "%p", hr::voidp(what));
dialog::addSelItem("mpdist", its(what->mpdist), 'd');
dialog::add_action([what] () {
bitfield_editor(what->mpdist, [what] (int i) { what->mpdist = 0; }, "generation level");
@ -561,7 +561,7 @@ EX void viewall() {
EX void modalDebug(cell *c) {
centerover = c; View = Id;
if(noGUI) {
fprintf(stderr, "fatal: modalDebug called on %p without GUI\n", c);
fprintf(stderr, "fatal: modalDebug called on %p without GUI\n", hr::voidp(c));
exit(1);
}
push_debug_screen();
@ -583,7 +583,7 @@ void test_distances(int max) {
EX void raiseBuggyGeneration(cell *c, const char *s) {
printf("procgen error (%p): %s\n", c, s);
printf("procgen error (%p): %s\n", hr::voidp(c), s);
if(!errorReported) {
addMessage(string("something strange happened in: ") + s);

View File

@ -832,7 +832,7 @@ EX void describeMouseover() {
if(c->land == laTortoise && tortoise::seek()) out += " " + tortoise::measure(getBits(c));
if(buggyGeneration) {
char buf[80]; sprintf(buf, " %p H=%d M=%d", c, c->landparam, c->mpdist); out += buf;
char buf[80]; sprintf(buf, " %p H=%d M=%d", hr::voidp(c), c->landparam, c->mpdist); out += buf;
}
if(randomPatternsMode)

View File

@ -35,6 +35,11 @@ template<class T>
void ignore(T&&) {
}
const void *voidp(const void *p) {
// a simple static_cast<void*> for use with printf("%p")
return p;
}
/** Is the value of first parameter equal to one of the remaining parameters? */
template<class T, class V, class... U> bool among(T x, V y) { return x == y; }
template<class T, class V, class... U> bool among(T x, V y, U... u) { return x==y || among(x,u...); }

View File

@ -144,7 +144,7 @@ void rebase(cellinfo& ci) {
cell *cx = ci.owner;
virtualRebase(ci.owner, ci.p);
if(ci.owner != cx) {
printf("rebased %p to %p\n", cx, ci.owner);
printf("rebased %p to %p\n", hr::voidp(cx), hr::voidp(ci.owner));
set_relmatrices(ci);
}
}
@ -463,7 +463,7 @@ bool step(int delta) {
int heptas = 0;
for(auto p: cells_of_heptagon) {
printf("%p: %d\n", p.first, isize(p.second));
printf("%p: %d\n", hr::voidp(p.first), isize(p.second));
heptas++;
}
@ -583,7 +583,7 @@ struct heptinfo {
EX map<heptagon*, heptinfo> periodmap;
EX void link_to_base(heptagon *h, heptspin base) {
// printf("linking %p to %p/%d\n", h, base.at, base.spin);
// printf("linking %p to %p/%d\n", hr::voidp(h), hr::voidp(base.at), base.spin);
auto &hi = periodmap[h];
hi.base = base;
for(int k: cells_of_heptagon[base.at]) {
@ -612,7 +612,7 @@ EX void link_start(heptagon *h) {
EX void link_next(heptagon *parent, int d) {
if(!periodmap.count(parent))
link_to_base(parent, heptspin(cells[0].owner->master, 0));
// printf("linking next: %p direction %d [s%d]\n", parent, d, parent->c.spin(d));
// printf("linking next: %p direction %d [s%d]\n", hr::voidp(parent), d, parent->c.spin(d));
auto *h = parent->move(d);
heptspin hs = periodmap[parent].base + d + wstep - parent->c.spin(d);
link_to_base(h, hs);
@ -625,7 +625,7 @@ EX void may_link_next(heptagon *parent, int d) {
EX void link_cell(cell *c, int d) {
// printf("linking cell: %p direction %d\n", c, d);
// printf("linking cell: %p direction %d\n", hr::voidp(c), d);
int ci = cellindex[c];
auto& sc = cells[ci];
int ci2 = sc.neid[d];
@ -644,7 +644,7 @@ EX void link_cell(cell *c, int d) {
heptspin hss(c->master, d);
hss += wstep;
master2 = hss.at;
// printf("master2 is %p; base = %p; should be = %p\n", master2, periodmap[master2].base.at, sc2.owner->master);
// printf("master2 is %p; base = %p; should be = %p\n", hr::voidp(master2), hr::voidp(periodmap[master2].base.at), hr::voidp(sc2.owner->master));
dirs++;
}
if(dirs != 1) { printf("dirs error\n"); exit(1); }
@ -674,7 +674,7 @@ map<heptagon*, heptagon*> last_on_horocycle;
void compute_horocycle(heptagon *);
void compute_distances(heptagon *h, bool alts) {
/* if(alts) printf("[%p] compute_distances %p\n", h->alt->alt, h);
/* if(alts) printf("[%p] compute_distances %p\n", hr::voidp(h->alt->alt), hr::voidp(h));
printf("neighbors:"); for(int i=0; i<S7; i++) printf(" %p", createStep(h, i)); printf("\n"); */
if(alts) {
@ -741,7 +741,7 @@ void erase_alt(heptagon *alt) {
void compute_horocycle(heptagon *alt) {
heptagon *master = last_on_horocycle[alt];
// printf("computing horocycle, master distance = %d [M=%p, A=%p]\n", master->alt->distance, master, alt);
// printf("computing horocycle, master distance = %d [M=%p, A=%p]\n", master->alt->distance, hr::voidp(master), hr::voidp(alt));
static const int LOOKUP = 16;
set<heptagon*> hs[LOOKUP];

View File

@ -480,14 +480,14 @@ void verify_crawlers() {
if(allcrawlers.count(id.first)) {
bool b = verify_crawler(allcrawlers[id.first], cellwalker(c, id.second));
if(!b) {
printf("cell %p: type = %d id = %d dir = %d / earlier crawler failed\n", c, c->type, id.first, id.second);
printf("cell %p: type = %d id = %d dir = %d / earlier crawler failed\n", hr::voidp(c), c->type, id.first, id.second);
failures++;
}
}
else {
for(int i=0; i<c->type; i++)
for(auto& cc: allcrawlers) if(verify_crawler(cc.second, cellwalker(c, i))) {
printf("cell %p: type = %d id = %d dir = %d / also works id %d in direction %d\n", c, c->type, id.first, id.second, cc.first, i);
printf("cell %p: type = %d id = %d dir = %d / also works id %d in direction %d\n", hr::voidp(c), c->type, id.first, id.second, cc.first, i);
uniq--;
goto breakcheck;
}