Raised This Month: $ Target: $400
 0% 

[Terrible Idea] Using the same function to set/get a string


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
humbugtheman
Member
Join Date: Jan 2012
Old 04-05-2016 , 17:41   [Terrible Idea] Using the same function to set/get a string
Reply With Quote #1

You shouldn't do this as it's pointless and ugly, but I put this together because I was interested in the idea. The Name function can be used to set or get a string, depending on what parameter you pass to it.
PHP Code:
// string 'type'
#define LENGTH 255
#define BUFFER "a_string_nobody_would_ever_use"

char g_Name[LENGTH];

public 
void OnPluginStart(){
    
    
// We set g_Name with the Name function
    
Name("Hello world!");
    
    
// We get g_Name with the Name function
    
char NameBuffer[LENGTH] = BUFFER;
    
Name(NameBuffer);
    
}

void Name(char[] Name){
    
    
// 'get'
    
if (IsBuffer(Name)){
        
strcopy(NameLENGTHg_Name);
    
    
// 'set'
    
} else {
        
strcopy(g_NameLENGTHName);
    }
}

bool IsBuffer(const char[] s){
    return 
StrEqual(sBUFFER);


Last edited by humbugtheman; 04-05-2016 at 17:41.
humbugtheman is offline
 



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 18:55.


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