Hewlett Packard OpenVMS has a C/C++ memset,_memset32 and _memset64 function

I found out today that Hewlett Packard OpenVMS has a C/C++ memset,_memset32 and _memset64 function. I am trying to fill the following 2 structs with 0 values and also non-0 values:

struct PZT64PropertyInformation{
    int64_t field1;
    int64_t field2;
    int64_t field3;
    int64_t field4;
    int64_t field5;
    int64_t field6;
    int64_t field7;
    int64_t field8;
    int64_t field9;
    int64_t field10;
    int64_t field11;
};

struct PZT32PropertyInformation{
    int32_t field1;
    int32_t field2;
    int32_t field3;
    int32_t field4;
    int32_t field5;
    int32_t field6;
    int32_t field7;
    int32_t field8;
    int32_t field9;
    int32_t field10;
    int32_t field11;
};

with the following C++ code in a C++ class method which is called by a managed C# assembly:
   PZT32PropertyInformation value;
    memset(&value,0, sizeof(PZT32PropertyInformation))
   
   c
    memset(&value,0, sizeof(PZT64PropertyInformation))

on a 64bit Lenovo desktop with Windows 7 Operating System and Microsoft Visual Studio 2008(64 bit C++ compiler) and MIcrosoft VIsual Studio 2013(C# managed code).

Could an expert(s) tell me if my PZT32PropertyInformation and PZT64PropertyInformation code could potentially cause garbage to be read or even worse a C++ or C# crash? Also, why does HP Open VMS provide an _memset32 and _memset64 in addition to memset?   Should I be using a handrolled version of _memset32 or _memset64? If so, what might its' code look like?
 
Thank you very much.
camster123Senior C++ Software EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sarabandeCommented:
tell me if my PZT32PropertyInformation and PZT64PropertyInformation code could potentially cause garbage to be read or even worse a C++ or C# crash?
no, the code is correct if the compiler doesn't complain that the arguments you supply don't fit to the argument types.

memset32 had a 32-bit pointer and 32 bit size argument - if i remember rightly. memset64 should be
equivalent to memset if your project is a 64-bit project (then using 64-bit pointers).  as already said, the compiler would complain when memset was called with the wrong arguments. the contents of the structure doesn't matter, what means it makes no difference whether it contains 64-bit or 32-bit members.

note, you could avoid an initial memset by code like

struct PZT64PropertyInformation values = { 0 };

which also sets all bytes of the structure to zero.

Sara
camster123Senior C++ Software EngineerAuthor Commented:
Sara,
   Thank you very much for your answer. You wrote earlier today that

>>note, you could avoid an initial memset by code like

>> struct PZT64PropertyInformation values = { 0 };

>> which also sets all bytes of the structure to zero.

I have another question. On a 64 bit Lenovo desktop computer running with Microsoft Visual Studio 2008 in debug 64-bit mode, what is the correct way to initialize struct PZT32PropertyInformation? Thank you,
sarabandeCommented:
any c or c++ compiler would be able to initialize an arbitrary struct or class without explicit constructor like

PZT32PropertyInformation values = { 0 };

if using c compiler you would need a typedef or use 'struct' keyword while with c++ you always can omit the struct keyword when defining a variable. class and struct are equivalent in c++ beside that the default for members is public for struct and private for class.

note, when defining a constructor or using class/struct members with a constructor, you need to provide initialization with the constructor. for reinitialization you could do

MyStruct x;   // MyStruct::MyStruct() called
x.doSomething();
x = MyStruct();    // reinit x with defaults

Sara

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.