SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 21/02/2014, 04:49 PM   #1
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,235
Reputation: 1004
Default Compiler stops working when including a file using backslashes

I have always included files using FORWARD slashes, for example:

pawn Code:
#include "files/scripts/test.inc"

But ****** recommended that I use BACKslashes instead, so I have started to. But there's one file that will include fine with forward slashes, but if I try and use BACKslashes, the compiler crashes..

This file is pretty much empty. It only has this in it:

pawn Code:
#define ADMIN_LEVEL_MOD 1
#define ADMIN_LEVEL_ADMIN 2
#define ADMIN_LEVEL_MANAGER 3
#define ADMIN_LEVEL_OWNER 4

new const AdminLevel[][] =
{
    "Player",
    "Moderator",
    "Admin",
    "Manager",
    "Owner"
};

new stock const AdminLevelPrefix[][] =
{
    "a player",
    "a moderator",
    "an admin",
    "a manager",
    "an owner"
};

This is the literal #include line:

pawn Code:
#include "files\scripts\staff\general.def"

To clarify exactly where this file is, my main .pwn file for my gamemode is in a folder called 'MNS' in the gamemodes directory, and inside that directory is another directory called 'files' which has all the other files in, which are included into the main .pwn file.

Using quotation marks in #include includes files that are relative to the file, so it's nothing to do with the pawno\include\ folder or using "..\" at the start.

Why is this happening? :/

Here's the directory itself, and the path:


All other files (at least 20) include perfectly fine with backslashes..
__________________
Owner and developer of Mike's Cops and Robbers.

Click here to visit our site and find out more. Click here to view trailers.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!
MP2 is offline   Reply With Quote
Old 21/02/2014, 05:30 PM   #2
ColeMiner
Banned
 
Join Date: Feb 2013
Location: 629
Posts: 166
Reputation: 88
Default Re: Compiler stops working when including a file using backslashes

I suspect this is something to do with the length:

pawn Code:
_inc_files/scripts/staff/genera

As the include-guard would be called when using forward slashes (not a valid name, but that's the problem with forward slashes) is 31 characters. When using "\" the separators are correctly identified and you get this:

pawn Code:
_inc_general

Thus, if you have another file called "general" in another folder, this one won't get included because the compiler thinks it already has been. This sounds like the best candidate for the problem (ignore what I started saying about length) - it MAY crash if you include code here that is needed, but it doesn't get included because of the mix-up with include guards.

I don't always recommend using "\" for exactly this reason - which to use varies by use-case. In your case you may want to instead use "/" since it worked anyway (just be aware of long directory chains).

Zeex's compiler doesn't automatically generate include guards so this won't be a problem there, but that can cause other issues if your files don't contain explicit include guards as required.
ColeMiner is offline   Reply With Quote
Old 21/02/2014, 05:35 PM   #3
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,235
Reputation: 1004
Default Re: Compiler stops working when including a file using backslashes

So if I use forward slashes, the include guard won't work properly because of the length? But I have 3 files included from the 'staff' folder and they all include correctly, but shouldn't the guard for them all be "_inc_files/scripts/staff/genera"? I'm confused.

Three files in 'staff':
infractions.pwn
general.def
functions.inc

If I include all these with forwardslashes, surely the include guard for all THREE of them would be the same (truncated to "_inc_files/scripts/staff/genera"), making the latter two not be included? But this isn't the case..
__________________
Owner and developer of Mike's Cops and Robbers.

Click here to visit our site and find out more. Click here to view trailers.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!
MP2 is offline   Reply With Quote
Old 21/02/2014, 05:45 PM   #4
ColeMiner
Banned
 
Join Date: Feb 2013
Location: 629
Posts: 166
Reputation: 88
Default Re: Compiler stops working when including a file using backslashes

The include guards for all three would be truncated, but you would end up with:

"_inc_files/scripts/staff/infrac"
"_inc_files/scripts/staff/genera"
"_inc_files/scripts/staff/functi"

Hence they would all still be included.
ColeMiner is offline   Reply With Quote
Old 21/02/2014, 05:48 PM   #5
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,235
Reputation: 1004
Default Re: Compiler stops working when including a file using backslashes

So would the best solution be to use backslashes and name the files uniquely? e.g. 'staff_general.def'?
__________________
Owner and developer of Mike's Cops and Robbers.

Click here to visit our site and find out more. Click here to view trailers.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!
MP2 is offline   Reply With Quote
Old 21/02/2014, 05:50 PM   #6
ColeMiner
Banned
 
Join Date: Feb 2013
Location: 629
Posts: 166
Reputation: 88
Default Re: Compiler stops working when including a file using backslashes

I'd just stick to forward slashes for now - the only problem comes when you include directories get too long, and even that can be fixed by mixing:

pawn Code:
#include "files\scripts\staff/general.def"

Would give an include guard name of "_inc_staff/general".

That may be enough to ensure that all your files are included and use backslashes more frequently.
ColeMiner is offline   Reply With Quote
Old 21/02/2014, 05:57 PM   #7
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,235
Reputation: 1004
Default Re: Compiler stops working when including a file using backslashes

Okay, thanks. Why do you recommend backslashes so often if it causes this problem?
__________________
Owner and developer of Mike's Cops and Robbers.

Click here to visit our site and find out more. Click here to view trailers.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!
MP2 is offline   Reply With Quote
Old 21/02/2014, 06:08 PM   #8
ColeMiner
Banned
 
Join Date: Feb 2013
Location: 629
Posts: 166
Reputation: 88
Default Re: Compiler stops working when including a file using backslashes

Because you can't do:

pawn Code:
#undef _inc_staff/general

"/" is not a valid symbol character so you can't detect or remove that guard. They both have problems, I just tended to favor "\" because it was used by YSI for the reason above, and because "\" is the native directory separator on Windows - the system most people use for development.
ColeMiner is offline   Reply With Quote
Old 21/02/2014, 06:15 PM   #9
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,235
Reputation: 1004
Default Re: Compiler stops working when including a file using backslashes

Heh, I just found this in YSI:

pawn Code:
// Yes - FORWARD slash here!
#include "y_als/impl"

I see now, thanks.
__________________
Owner and developer of Mike's Cops and Robbers.

Click here to visit our site and find out more. Click here to view trailers.
Enter referral code SAMPFORUM after registering for a $5000 starting bonus!
MP2 is offline   Reply With Quote
Old 21/02/2014, 11:48 PM   #10
ColeMiner
Banned
 
Join Date: Feb 2013
Location: 629
Posts: 166
Reputation: 88
Default Re: Compiler stops working when including a file using backslashes

Yes, almost all the "impl.inc" files (there is now one for almost every library in the framework) are included that way for the reason above of getting unique include-guard names. The files that start with an underscore are all included using "\", and are all included multiple times so use the well-definedness of their guard names to #undef them so that they can be included multiple times.
ColeMiner is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pawn compiler stops working. Kyance Scripting Help 6 01/01/2014 11:57 AM
Pawno Compiler Library Stops Working Th3b3ast5 Scripting Help 20 17/05/2013 10:37 PM
Pawn Compiler Library Stops Working Th3b3ast5 Scripting Help 3 04/05/2013 11:12 PM
Compiler Stops working but Brackets are fine...Help ArmandoRamiraz Scripting Help 25 20/07/2012 07:35 PM
including .pwn file Larry123 Scripting Help 9 17/01/2012 12:23 PM


All times are GMT. The time now is 03:31 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.