简体   繁体   中英

EXC_BAD_ACCESS on for loop (array function pointer)

The following code is causing a EXC_BAD_ACCESS address 0x0 error - even when i is correct somehow. It's used to execute the arrays pointed to the functions. If I change the sizeof(draw); with the number i have, it just works as expected.

 for(int i = 0; i < sizeof(draw); i++)
        draw[i](i);

sizeof(draw) returns the size of "draw" in number of bytes, not number of items. You are probably looking for (sizeof(draw)/sizeof(draw[0]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM