Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Problems with ALLEGRO_FONT

Credits go to Edgar Reynaldo for helping out!
This thread is locked; no one can reply to it. rss feed Print
Problems with ALLEGRO_FONT
Aleksa
Member #14,874
January 2013

I get two compile errors for ALLEGRO_FONT *fonts[FONT_MAX]; in graphics.h :
- syntax error: missing '{' before '*'
- identifier "ALLEGRO_FONT" is undefined

Strange thing is that ALLEGRO_BITMAP and ALLEGRO_DISPLAY work ok. If I include allegro_fonts in main or that exact .h file it works but that's not what i should do?
Any help?

graphics.h

#SelectExpand
1#pragma once 2 3enum { 4 IMAGE_BACKGROUND, 5 IMAGE_MAX 6}; 7 8enum { 9 FONT_PROGGYCLEANSZ_23, 10 FONT_MAX 11}; 12 13ALLEGRO_BITMAP *images[IMAGE_MAX]; 14ALLEGRO_FONT *fonts[FONT_MAX]; 15ALLEGRO_DISPLAY *display;

graphics.c

#SelectExpand
2#include <allegro5\allegro.h> 3#include <allegro5\allegro_native_dialog.h> 4#include <allegro5\allegro_image.h> 5#include <allegro5\allegro_font.h> 6#include <allegro5\allegro_ttf.h> 7#include <allegro5\allegro_primitives.h> 8 9#include "graphics.h" 10 11 12//LOADING STUFF

Edgar Reynaldo
Member #8,592
May 2007
avatar

Aleksa
Member #14,874
January 2013

Including header file works, predeclare does not.
Any idea why other types as ALLEGRO_BITMAP and ALLEGRO_DISPLAY work?

Edgar Reynaldo
Member #8,592
May 2007
avatar

Aleksa
Member #14,874
January 2013

With typedef i get: 'typedef ': ignored on left of 'ALLEGRO_FONT' when no variable is declared

These are only headers i include in main.c
Are ALLEGRO_BITMAP and ALLEGRO_DISPLAY defined in allegro.h?

main.c headers

#SelectExpand
1#include <stdbool.h> 2#include <stdio.h> 3 4#include <allegro5\allegro.h> 5#include <allegro5\allegro_native_dialog.h> 6 7#include "keyboard.h" 8#include "graphics.h"

edit: I just peeked at allegro.h and it includes bitmap.h that defines ALLEGRO_BITMAP. This solves my confusion :)
Thanks :)

Edgar Reynaldo
Member #8,592
May 2007
avatar

Since you're using C I think you need to include 'struct' anytime you declare a variable of that type, unless it is after it has been typedef'ed.

struct ALLEGRO_FONT* font[3];

#include "allegro5/allegro_font.h"
/** in allegro_font.h
typedef struct ALLEGRO_FONT {...};
*/


ALLEGRO_FONT* font;

Aleksa
Member #14,874
January 2013

That works!

#SelectExpand
1struct ALLEGRO_FONT *font[FONT_MAX];

Go to: