If we do not include any header files in VC, for example in a console
application from an empty project, will VC automatically include some header
files for us?
My confusion is from the size_t discussion, in the discussion we could use
size_t without include any files, but in MSDN it is mentioned size_t is
defined in crtdef.h.
thanks in advance,
George
I don't think so, but at the same time the compiler is free to define
some types as *extensions* to the language. Extensions don't have to be
provided as additional code you need to include through some headers.
BTW, how do you make a useful console application without including any
headers? Are you going to declare the needed functions yourself? How
do you know you do it correctly? The correspondence between the library
object files that you link to your application and the headers is only
assured if you include the headers that declare the functions you're
going to use. And if you're not going to use any functions, it's likely
that your program will have no observable behaviour...
> My confusion is from the size_t discussion, in the discussion we could use
> size_t without include any files, but in MSDN it is mentioned size_t is
> defined in crtdef.h.
As soon as you include any header, it's very likely the other headers,
like <crtdef.h> are going to be included as well.
My confusion is, why do you care? What problem are you trying to solve?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
> As soon as you include any header, it's very likely the other headers,
> like <crtdef.h> are going to be included as well.
My concern is previously I always follow MSDN and think if we do not include
required headers, the included asset like siez_t could not be used. But after
I tried without including crtdef.h, we could also use size_t -- it
contradicts my concept of both follow MSDN to include header file and VC does
not automatically include something for us. :-)
regards,
George
It doesn't include anything, put some functions are "implicitly
defined" anyway. By magic!
The standard says (3.7.3) that these functions must somehow be
available in all translation units, even if you don't include
anything:
void* operator new(std::size_t) throw(std::bad_alloc);
void* operator new[](std::size_t) throw(std::bad_alloc);
void operator delete(void*) throw();
void operator delete[](void*) throw();
The compiler is supposed to do this so that new, new[], delete, and
delete[] are visible, BUT std, bad_alloc, and size_t are not.
Obviously it fails slightly, and there is a name leak!
Bo Persson
What you mentioned is the C++ Spec, the standard. Do you have any
information if VC pre-includes anything (like header file, function like new
or type like size_t)?
regards,
George
George, it absolutely does not matter. Bo's message represents an
interesting piece of trivia, but exploring this point will do NOTHING
towards helping you to write better programs.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
Generally I agree with you. My confusion is, I am writing code for both x64
and x86, and I am using size_t type. I assume size_t for x64 is always 8
bytes and for x86 is 4 bytes.
Such information is very important for me. But when in this discussion I
found there are a couple of files defined size_t, then I am very confused and
want to find whether I may meet some issues in the future when size_t size
changed in either x86 or x64 because of using different header with different
definitions? Just something like this.
Do you have any advice or comments for my concern and situation?
regards,
George
If size_t is somehow declared differently in system header files it's
a pretty fundamental mistake for the compiler vendor to make.
Stop worrying about it.
Dave
I will just make size_t a top secret of VC which we could not explain from
our normal rules. :-)
regards,
George