This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Add uninitialized attribute?


Kreitzer, David L wrote:

> There are some situations where an __undefined__ keyword would be useful

Thanks for the example.

I suppose that in C the natural syntax is a pseudo-function that takes a
type, rather than an object, as an argument:

  __undefined__(int)
  __undefined__(vector float)
  ...

In GCC, at least, __undefined__ could be a macro, for the purposes of
defining its semantics:

  #define __undefined__(T) \
    ({ T t; t })

That is, create an new variable of type T, do not initialize it, and use
its value.

But, we would not issue warnings about it.

The macro definition is possibly also useful in that I think it says the
right thing for C++.  In particular, in C++, for a class that has
constructors, constructors should run.  You *should not* be able to say:

  __undefined__(std::vector<int>)

and somehow bypass the constructor.  That violates key assumptions of
the programming model in C++.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]