Global variables in C

Hi All,

For our requirement ,we are creating the global variables like
GlobalValue *GV = new GlobalVariable(M, Type::getInt32Ty(*Context), false,
                                       GlobalValue::ExternalLinkage, nullptr,

where "Name" is the global name with "Extern or Internal" Linkage .

Say "Name=foo" is already in the Module and when we try to create
"GlobalVariable" Instance again for "Name=foo" ,the current semantics
of GlobalVariable() is that ,it renames like "foo.<random number>" i.e
"foo.10" .

Currently we are overriding this semantics by iterating the
Module.globals() and if "Name"doesn't exist ,the we are creating the
new instance else we get the reference to it .

Is that better way to do so ?

Thank you

Hi Umesh,