Checking if a function exists at compile time: native function failed at run time
#1

I need to check if a function is defined(for an include). So I wrote this code:
pawn Код:
#if !defined fcreate
    stock fcreate(const filename[])
    {
        printf("Fcreatea: start");
        if(!fexist(filename))
        {
            printf("Fcreatea: the file does Not exist");
            new File:file = fopen(filename,io_write);
            printf("Fcreatea: file opened");
            return fclose(file);
        }
        return 0;
    }
#endif
And a backtrace from crashdetect:
pawn Код:
[18:49:49] [debug] Run time error 10: "Native function failed"
[18:49:49] [debug]  fread
[18:49:49] [debug] AMX backtrace:
[18:49:49] [debug] #0 00000c50 in public OnGameModeInit () from speed.amx
I used the function in OnGameModeInit hook:
pawn Код:
printf("File does NOT exist");
        fcreate(BAN_FILE_NAME);
I left those prints there for a reason. This is the last thing printed out before "Native function failed":
pawn Код:
[18:49:49] File does NOT exist
Which is just before calling the function "fcreate"

If I remove the #if !defined part, it runs just like it should. But this is not a sollution.


All ideas will be appreciated
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)