Raised This Month: $12 Target: $400
 3% 

Solved Trying to get rid of a few warnings (loose indentation, unreachable code)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mordekay
Squirrel of Fortune
Join Date: Apr 2006
Location: Germany
Old 01-08-2019 , 06:29   Trying to get rid of a few warnings (loose indentation, unreachable code)
Reply With Quote #1

As the topic says, i'm trying to get rid of these warnings. I was able to remove most of them myself, but those are over my abilities.
Code:
AMX Mod X Compiler 1.9.0.5235
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2013 AMX Mod X Team

war3ft/cvar.inl(95) : warning 217: loose indentation
war3ft/cvar.inl(102) : warning 217: loose indentation
war3ft/race_crypt.inl(248) : warning 225: unreachable code
war3ft/clientCommands.inl(72) : warning 225: unreachable code
war3ft/menus.inl(173) : warning 217: loose indentation
war3ft.sma(682) : warning 225: unreachable code
Header size:           8912 bytes
Code size:           338208 bytes
Data size:           227784 bytes
Stack/heap size:      16384 bytes
Total requirements:  591288 bytes

6 Warnings.
Done.
Attached the complete scripting files and the files in question in a separate archive.
Attached Files
File Type: zip scripting.zip (129.7 KB, 69 views)
File Type: zip filesinquestion.zip (20.6 KB, 40 views)
__________________


Last edited by Mordekay; 01-08-2019 at 12:59.
Mordekay is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-08-2019 , 06:44   Re: Trying to get rid of a few warnings (loose indentation, unreachable code)
Reply With Quote #2

Unreachable code happens when you have
PHP Code:
if(expression1) {
    
// if-code
    
return expression2;
} else {
    
// else-code
    
return expression3;
}

// more code, even if it's just another "return" 
"more code" part is unreachable because the function will return in any case (both if and else) before that. To easily fix this you can either remove all code in the "more code" part, or refactor it to:
PHP Code:
if(expression1) {
    
// if-code
    
return expression2;
}

// else-code
return expression3
Loose indentation happens when you mix tabs and spaces to indent lines. You have to be consistent.
__________________

Last edited by klippy; 01-08-2019 at 06:46.
klippy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-08-2019 , 06:50   Re: Trying to get rid of a few warnings (loose indentation, unreachable code)
Reply With Quote #3

Can't check the files right now, but loose indentation just means the code is not alligned properly in the sma file, has no effect over the amxx file and can be ignored.
unreachable code means usually that at some point you unconditionally return(return some_value) and after that you have more code. The code after return will never get executed because a return stops the execution of the function. That code can be removed, unless the return is wrongly placed.
__________________
HamletEagle is offline
Mordekay
Squirrel of Fortune
Join Date: Apr 2006
Location: Germany
Old 01-08-2019 , 06:54   Re: Trying to get rid of a few warnings (loose indentation, unreachable code)
Reply With Quote #4

For the indentations I've already tried to replace all spaces with tabs and vice versa, it didn't fixed the warning.
For the unreachable code: what?!?! I have no idea about coding, so as said: this is over my abilities. For me simply removing code because it is not reachable doesn't make sense. It was written for a reason, just a mistake doesn't make it useless. Please correct me if I am wrong.

Ah! I got that now. Ok, I've fixed the unreachable code errors now. Just the loose indentations are left.
__________________


Last edited by Mordekay; 01-08-2019 at 07:01.
Mordekay is offline
TudorLaLeagane
Junior Member
Join Date: Mar 2018
Old 01-08-2019 , 07:33   Re: Trying to get rid of a few warnings (loose indentation, unreachable code)
Reply With Quote #5

You can let those, it doens't affect the .amxx at all.
TudorLaLeagane is offline
Mordekay
Squirrel of Fortune
Join Date: Apr 2006
Location: Germany
Old 01-08-2019 , 07:33   Re: Trying to get rid of a few warnings (loose indentation, unreachable code)
Reply With Quote #6

I know that, thanks.
__________________

Mordekay is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-08-2019 , 08:00   Re: Trying to get rid of a few warnings (loose indentation, unreachable code)
Reply With Quote #7

In notepad++

You can try select all text/code, hit TAB and tab backwards with Shift+TAB.

Another thing you can try, install NppTextFX plugin, then select all text/code and use "TextFX->TextFX edit->Reindent C++ code" (I remember @Mitchell mention this in one of post)

*
from View-> Show symbols -> Show White spaces and TAB


*edit
uu what I found
[TUT][HQ] Indenting your code in proper way!

Last edited by Bacardi; 01-08-2019 at 08:05.
Bacardi is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-08-2019 , 08:43   Re: Trying to get rid of a few warnings (loose indentation, unreachable code)
Reply With Quote #8

Basically, if a part of the code looks like this:

PHP Code:
public OnRoundRestart()
     {
 
g_iRounds 0
             g_iTScore 
0
    g_iCTScore 
0
   

You should make it look like this:

PHP Code:
public OnRoundRestart()
{
    
g_iRounds 0
    g_iTScore 
0
    g_iCTScore 
0

If you use enter+tab only after a "{" bracket, you shouldn't have any problems.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Mordekay
Squirrel of Fortune
Join Date: Apr 2006
Location: Germany
Old 01-08-2019 , 08:58   Re: Trying to get rid of a few warnings (loose indentation, unreachable code)
Reply With Quote #9

With that tutorial it was easy, thanks Bacardi!
__________________

Mordekay is offline
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

Forum Jump


All times are GMT -4. The time now is 22:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode