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

How to initialize an static array of type struct


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
UeberDaniel
AlliedModders Donor
Join Date: Dec 2009
Location: Germany
Old 01-12-2020 , 09:01   How to initialize an static array of type struct
Reply With Quote #1

Hi,

How can i get this working?

PHP Code:
enum struct position {
  
float x;
  
float y;
  
float z;
}

enum struct area {
  
position min;
  
position max;
}

static 
area blockedArea[1] = {  .min.= -871.968750, .max.1509.968750,
                                .
min.4244.035645, .max.=  5009.968750,
                                .
min.336.031250, .max.=  336.031250   }; 
Gives me this Error on line "static area blockedArea":
error 029: invalid expression, assumed zero

If i try this:
PHP Code:
static area blockedArea[1] = {  -871.9687501509.968750,
                                
4244.0356455009.968750,
                                
336.031250336.031250   }; 
I get this Error on line "static area blockedArea":
warning 213: tag mismatch
error 018: initialization data exceeds declared size

So how can i initialize this area correctly?

Greetings
__________________

UeberDaniel is offline
Send a message via MSN to UeberDaniel
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 01-12-2020 , 14:15   Re: How to initialize an static array of type struct
Reply With Quote #2

static area a = { { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 } };

Looks like there's a compiler bug if you use plain integers, though (like 1 instead of 1f or 1.0).
Fyren is offline
UeberDaniel
AlliedModders Donor
Join Date: Dec 2009
Location: Germany
Old 01-12-2020 , 15:50   Re: How to initialize an static array of type struct
Reply With Quote #3

Got it compiling now but idk why I still get Tag Mismatch warnings:
PHP Code:
enum struct position {
  
float x;
  
float y;
  
float z;
}

enum struct area {
  
position min;
  
position max;
}

static 
area blockedArea[1] = {{  {-871.9687504244.035645336.031250},
                                {
1509.968750,  5009.968750336.031250} }}; 
Line "static area blockedArea[1]" and next:
Code:
warning 213: tag mismatch
warning 213: tag mismatch
__________________


Last edited by UeberDaniel; 01-12-2020 at 15:57.
UeberDaniel is offline
Send a message via MSN to UeberDaniel
BHaType
Great Tester of Whatever
Join Date: Jun 2018
Old 01-12-2020 , 19:39   Re: How to initialize an static array of type struct
Reply With Quote #4

Code:
static area blockedArea[1] = {{  view_as<float>({-871.968750, 4244.035645, 336.031250}),
                                view_as<float>({1509.968750,  5009.968750, 336.031250}) }};
I didnt test but it should help
__________________
cry
BHaType is offline
Send a message via AIM to BHaType
UeberDaniel
AlliedModders Donor
Join Date: Dec 2009
Location: Germany
Old 01-14-2020 , 12:00   Re: How to initialize an static array of type struct
Reply With Quote #5

This is just generating another error:

PHP Code:
static area blockedArea[1] = {{  view_as<float>({-871.9687504244.035645336.031250}),
                                
view_as<float>({1509.968750,  5009.968750336.031250}) }}; 
Code:
error 008: must be a constant expression; assumed zero
error 008: must be a constant expression; assumed zero
__________________

UeberDaniel is offline
Send a message via MSN to UeberDaniel
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 15:26.


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