Compiler crash [with function pointers].

Discussion about writing software for VS1005 and the VSOS Operating System. Also posts about VS1005-related hardware design and device drivers should be posted here.
Post Reply
jedm@vpitech.com
Senior User
Posts: 50
Joined: Wed 2016-11-02 22:50

Compiler crash [with function pointers].

Post by jedm@vpitech.com » Fri 2016-12-23 21:19

I'm trying to build a constant array of functions:

Code: Select all

typedef void *(fn)(void);
fn *X[3];
causes the compiler to crash:
Build started. Project: aplayer, configuration: Emulation-Debug

lcc -g -hhw_desc -O6 -fsmall-code -DDEBUGAPLAYER -DDEVBOARD -DVSDSP -DDEBUG -Iinclude -IC:\Users\jedm\VSIDE\libvs1005g_vsos3 -o Emulation-Debug\test.o C:\Users\jedm\clients\audioflood\mp3player\source\aplayer\test.c

C:\Users\jedm\VSIDE\bin\make.exe: *** [all] Error -1073741819
And followed by asking about sending you a crash message (which I didn't).

User avatar
Panu
VLSI Staff. Currently on holiday.
Posts: 2714
Joined: Tue 2010-06-22 13:43

Re: Compiler crash.

Post by Panu » Sat 2016-12-24 5:13

Hi...

Shouldn't it be void (*fn)(void) instead of void *(fn)(void) ?

Code: Select all

#include <stdio.h>

typedef void (*fn)(void);
fn *X[3];

void main(void) {
	puts("Hello, world!");
	while (1) {    
	}
}
compiles successfully.

And why the extra * in fn *X[3]? Shouldn't it be fn X[3]? If fn is a function pointer, then fn X[3] is an array of three function pointers, but fn *X[3] declares pointers to function pointers, which is not often needed. Both compile ok.

Here's a little test program that runs ok in the simulator and prints "test" when run. I attached it below, so you can try it yourself!

Code: Select all

#include <stdio.h>

typedef void (*fn)(void);
fn X[3];

void test(void) {
	puts("test");
}

void main(void) {
	X[0] = test;
	X[0]();	
}
-Panu
Attachments
arch-fnp-2016-12-24-05-20-ok.zip
Function pointer test solution. Runs in the simulator, no hardware needed. VSIDE Solution source code.
(2.68 KiB) Downloaded 63 times
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy

jedm@vpitech.com
Senior User
Posts: 50
Joined: Wed 2016-11-02 22:50

Re: Compiler crash [with function pointers].

Post by jedm@vpitech.com » Wed 2016-12-28 17:17

My apologies. You are correct. I thought I'd checked that combination, it must have been some other error.

User avatar
Panu
VLSI Staff. Currently on holiday.
Posts: 2714
Joined: Tue 2010-06-22 13:43

Re: Compiler crash [with function pointers].

Post by Panu » Thu 2016-12-29 7:18

Hi!

Please, no apologies necessary!

I am here to help and I'm very glad I was able to help you!

-Panu
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy

Lasse
VLSI Staff
Posts: 27
Joined: Tue 2010-06-22 13:30

Re: Compiler crash [with function pointers].

Post by Lasse » Tue 2017-01-03 18:15

The line "typedef void *(fn)(void)" declares the type of "function returning a pointer to void", i.e. not a pointer to a function. I think the original code should declare an array of pointers to functions returning void pointers. From the top of my head I can't remember if the ANSI specification supports this kind of typedef, but either way, its sensible code that should definitely produce something else than a compiler crash :D

Thanks for letting us know. I'll try to remember to look into this.
Software Designer
VLSI Solution

Post Reply