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

Possibly erroneous warning when declaring enum structs with primitive members


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Sappykun
Member
Join Date: Nov 2019
Old 03-03-2021 , 23:03   Possibly erroneous warning when declaring enum structs with primitive members
Reply With Quote #1

I have the following snippet of code:

PHP Code:
enum struct Survivor1 {
  
char name[MAX_NAME_LENGTH];
  
char model[PLATFORM_MAX_PATH];
  
int prop;
  
char adminflags[16];
}

enum struct Survivor2 {
  
char name[MAX_NAME_LENGTH];
  
char model[PLATFORM_MAX_PATH];
  
int prop[1];
  
char adminflags[16];
}

public 
void OnPluginStart()  
{
    
Survivor1 e = { "Ellis""models/survivors/survivor_mechanic.mdl"3"bcd" }; // line 17
    
Survivor2 z = { "Zoey""models/survivors/survivor_teenangst.mdl"5"z" };
    
    
PrintToServer("%s %s %i %s"e.namee.modele.prope.adminflags);
    
PrintToServer("%s %s %i %s"z.namez.modelz.propz.adminflags); // line 21

Compiling this code produces the following warning:

test.sp(17) : warning 228: length of initializer exceeds size of the enum field

but otherwise compiles perfectly fine.

I am confused by this, especially since activating the plugin doesn't throw any errors:

Code:
sm plugins load custom/optional/test
Ellis models/survivors/survivor_mechanic.mdl 3 bcd
Zoey models/survivors/survivor_teenangst.mdl 5 z
[SM] Loaded plugin custom/optional/test.smx successfully.
If I change the PrintToServer lines to the following:
PHP Code:
PrintToServer("%s %s %i %s"e.namee.modele.prop 4e.adminflags);
PrintToServer("%s %s %i %s"z.namez.modelz.prop 4z.adminflags); 
and attempt to recompile, I get this error:

test.sp(21) : error 033: array must be indexed (variable "prop")

Why do I need to declare prop as an array to make the warning go away? IntToString (which is used in my plugin to apply the prop's value to a player) doesn't accept integer arrays, and I can't perform operations on z.prop without referencing index 0 constantly.

I have a feeling that my code (Survivor1 specifically) is fine, and the compiler is throwing a false warning. Can someone with more SourcePawn experience confirm or deny my suspicions?

Last edited by Sappykun; 03-07-2021 at 00:44.
Sappykun 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 05:34.


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