Raised This Month: $32 Target: $400
 8% 

Solved How to allow empty statements?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 10-21-2018 , 13:41   How to allow empty statements?
Reply With Quote #1

Hi,

Ho to make this without errors/warnings ?

(for better formatting purposes), like:
Code:
if (!foo(0, a))
if (!foo(1, a))
if (!foo(2, a))
{};
instead of:
Code:
if (!foo(0, a))
if (!foo(1, a))
foo(2, a);
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 10-21-2018 at 21:07.
Dragokas is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 10-21-2018 , 15:02   Re: How to allow empty statements?
Reply With Quote #2

Not really sure what your question is. Neither of those snippets really make any sense?
__________________
ddhoward is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 10-21-2018 , 15:50   Re: How to allow empty statements?
Reply With Quote #3

Sorry, I mean, 1-st snippet cannot be compiled, because:

Quote:
1.sp(7) : error 036: empty statement
because empty {} is not permitted.

The question is just about convenient code formatting.

Maybe just use dummy:
Code:
public OnPluginStart()
{
	int a;

	if (!foo(0, a))
	if (!foo(1, a))
	if (!foo(2, a))
		dummy();
}

bool foo(int p1, int p2)
{
	return (p1 == p2);
}

void dummy() {}
So, maybe language provides simplier walkaround instead of "dummy"?

Well, don't pay attention. Stupid question.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 10-21-2018 , 15:58   Re: How to allow empty statements?
Reply With Quote #4

Code:
public void OnPluginStart()
{
	int a = 0;

	if (!foo(0, a) && !foo(1, a) && !foo(2, a))
		dummy();
}

bool foo(int p1, int p2)
{
	return (p1 == p2);
}

stock void dummy()
{
	// code
}
__________________
Neuro Toxin is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 10-21-2018 , 17:29   Re: How to allow empty statements?
Reply With Quote #5

You don't even need the if statements.
Code:
public void OnPluginStart()
{
    int a = 0;
    !foo(0, a) &&
    !foo(1, a) &&
    !foo(2, a);
}
__________________
klippy is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 10-21-2018 , 18:23   Re: How to allow empty statements?
Reply With Quote #6

U can have empty if statements...i use them when needed...im betting the semicolon at the end is causing your error...like if this statement true...dont do anything...but if its giving u issues. Just put a return in the empty statement?
MasterMind420 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 10-21-2018 , 18:29   Re: How to allow empty statements?
Reply With Quote #7

Empty statements is just bad design. Pretty much any language that has a findbugs type plugin will see it as a bad conventions.

Last edited by Mitchell; 10-21-2018 at 18:31.
Mitchell is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 10-21-2018 , 18:36   Re: How to allow empty statements?
Reply With Quote #8

Quote:
Originally Posted by Mitchell View Post
Empty statements is just bad design. Pretty much any language that has a findbugs type plugin will see it as a bad conventions.
Empty statements have there uses...not sure why everyone is using && either...

Code:
if(!foo(0, a) || !foo(1, a) || !foo(2, a))
{

}
this should compile fine...
MasterMind420 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-21-2018 , 19:03   Re: How to allow empty statements?
Reply With Quote #9

Quote:
Originally Posted by MasterMind420 View Post
Empty statements have there uses...
They really don't, after all, they're empty.

There's a difference between empty statements and statements intentionally designed to take up processor cycles without doing anything... and even those are indicative of bad design.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 10-21-2018 , 19:39   Re: How to allow empty statements?
Reply With Quote #10

Quote:
Originally Posted by Powerlord View Post
They really don't, after all, they're empty.

There's a difference between empty statements and statements intentionally designed to take up processor cycles without doing anything... and even those are indicative of bad design.
All i see it affecting is readability...thats it...wether u do it one way or the other effects absolutely nothing else. I'm not arguing its not better to avoid empty if statements. I'm just saying they work the same regardless...if there's an else after...just an if statement is pointless and wont do anything. i'm not even really sure what this guys trying to do.
MasterMind420 is offline
Reply



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 05:13.


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