Click here to Skip to main content
14,691,457 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
by the way am developing my kernel driver i know c++ but am new to C syntax

thanks for helping in advance

What I have tried:

first i had my struct in my .c file but i want to initialize my vars in global space instead of giving my vars to local. so i have tried to do it this way

in my header file but it didn't work it said type error i googled but no luck

struct Orginal
{
	PDRIVER_OBJECT driver_object; // NULL
	PDRIVER_UNLOAD unload;  // NULL
	PDRIVER_DISPATCH major_functions[IRP_MJ_MAXIMUM_FUNCTION + 1]; //{ NULL };
	PDEVICE_OBJECT device;  // NULL
	BOOLEAN destroy_device; // bool false
	ULONGLONG guard_icall; // 0
};

struct orginal org;


org = { .driver_object = NULL ,.unload = NULL , .device = NULL , .destroy_device = false , .guard_icall  = 0};


this time when i tried to do it in local functions it works fine

orginal org;
org.device = NULL;
org.destroy_device = false;
org.guard_icall = 0;
//org.major_functions = NULL;
org.driver_object = NULL;
org.unload = NULL;
Posted
Updated 27-Jan-19 5:30am
Comments
KarstenK 27-Jan-19 4:35am
   
Best is to write an initializer in some startup/entry function.

Your attempt had a seperate instruction so it was not the right syntax for initialization. Try this :
struct orginal org = { NULL, NULL, NULL, NULL, false, 0 };
   
Comments
Member 14130865 26-Jan-19 22:48pm
   
@Rick York now org is (incomplete type is not allowed)
Rick York 27-Jan-19 13:05pm
   
What happens if you write,

Orginal org = { NULL, NULL, NULL, NULL, false, 0 };

?
now org is (incomplete type is not allowed)

C - just like C++ - is case sensitive, so original is not the same as Original.
Try:
struct Orginal
{
	PDRIVER_OBJECT driver_object; // NULL
	PDRIVER_UNLOAD unload;  // NULL
	PDRIVER_DISPATCH major_functions[IRP_MJ_MAXIMUM_FUNCTION + 1]; //{ NULL };
	PDEVICE_OBJECT device;  // NULL
	BOOLEAN destroy_device; // bool false
	ULONGLONG guard_icall; // 0
};

struct Orginal org = { .driver_object = NULL ,.unload = NULL , .device = NULL , .destroy_device = false , .guard_icall  = 0};
Note: this will only work in C99 or later (ANSI C) - designated initializers did not exist in C prior to that.
   
Comments
Member 14130865 27-Jan-19 12:59pm
   
@OriginalGriff thanks man +REP
OriginalGriff 27-Jan-19 13:37pm
   
You're welcome!
Simpler way

struct Orginal org = {0};
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900