I’ve reviewed many of the previous entries for this, but can’t figure out why my (seemingly simple) construct doesn’t work:
I want to create an array of pointers to previously-defined strings (char *). Here’s my
construct:
<code>const char *gs_Floatx0_FMT = "%c%4.0f %4.0f %4.0f %4.0f";
const char *gs_Floatx1_FMT = "%c%4.1f %4.1f %4.1f %4.1f";
const char *gs_Floatx2_FMT = "%c%4.2f %4.2f %4.2f %4.2f";
const char *gs_Floatx3_FMT = "%c%4.3f%4.3f%4.3f%4.3f";
const char *gsa_Fmt_Tbl[] = {
gs_Floatx0_FMT, gs_Floatx1_FMT,
gs_Floatx2_FMT, gs_Floatx3_FMT};
</code>
<code>const char *gs_Floatx0_FMT = "%c%4.0f %4.0f %4.0f %4.0f";
const char *gs_Floatx1_FMT = "%c%4.1f %4.1f %4.1f %4.1f";
const char *gs_Floatx2_FMT = "%c%4.2f %4.2f %4.2f %4.2f";
const char *gs_Floatx3_FMT = "%c%4.3f%4.3f%4.3f%4.3f";
const char *gsa_Fmt_Tbl[] = {
gs_Floatx0_FMT, gs_Floatx1_FMT,
gs_Floatx2_FMT, gs_Floatx3_FMT};
</code>
const char *gs_Floatx0_FMT = "%c%4.0f %4.0f %4.0f %4.0f";
const char *gs_Floatx1_FMT = "%c%4.1f %4.1f %4.1f %4.1f";
const char *gs_Floatx2_FMT = "%c%4.2f %4.2f %4.2f %4.2f";
const char *gs_Floatx3_FMT = "%c%4.3f%4.3f%4.3f%4.3f";
const char *gsa_Fmt_Tbl[] = {
gs_Floatx0_FMT, gs_Floatx1_FMT,
gs_Floatx2_FMT, gs_Floatx3_FMT};
The error I get is “main.c:40:15: error: (188) constant expression required”
Each FMT is a constant char pointer. Therefore, doesn’t const char *gsa_Fmt_Tbl[] create an array of char pointers?
New contributor
MikeTheButcher is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.