C
c prog fan
jameskuyper said:Keep in mind that the C and C++ standards don't distinguish between
compile time and run-time; they only talk about translation and
execution of a program. A conforming implementation could produce an
executable file that contains a copy of the source code files, and
doesn't actually perform any of the translation phases on those files
until just before each execution of the program.
Please correct these aloud thinkings if they are to be :
Well I have used my mind like an embedded device; what do you expect
from me then ?
I think this distinction is an excellent point to consider the
difference; for instance an implementation might leave some part of OS
related stuff to cope with when the program executes (char set comes to
mind); obviously those parts should not be (very) resource consuming
from a practical point of view.
If the compiler is able to predict with a certainty what the argument
of a given cast operator will be, before the program has even started
executing, it may be able to evaluate it during translation. In
general, this requires that the argument of the cast be a constant
expression, but a sufficiently smart compiler can look at an
algorithm, pre-determine what the result of applying that algorithm
will be, and optimize the program by just generating code for that
result, without actually generating any code for executing the
algorithm.
Sure this may happen but mainly I wanted to point that from a code
providing perspective it is not unlikely that this may not happen so one
has to put this into consideration. Say expecting worst case behavior.
Some casts are allowed inside of what C calls "integer constant
expressions", and what C++ calls "integral constant expressions" (I'll
just call them ICE's). An ICE that occurs in a context where an ICE is
required (contexts such as array lengths, case expressions, etc.) must
be evaluated during translation.
This is again interesting for me. The naming indicates that the is a
meaningful difference between the two. Thinking furthur I conclude that
C++ ICE might include C ICE as well as other types which are used for
static typing. This is not a suprize anyway because of templates of C++
and user defined types of it ( at least as I have heard of ).
[...]Casts involving pointers and references cannot be evaluated until the
things those pointers and references refer to have been given actual
memory locations.
Can you explain a bit why this is not possible ? (Obviously I fail to
understand this ...)
What can occur during translation, with either language, is detection
of the fact that a given use of cast operator may make issuance of a
diagnostic message by the compiler mandatory. The difference between
the two languages is that diagnostics are mandatory for the named C++
casts under a much wider variety of circumstances than C casts. No
macro wrapper for a C cast can simulate that feature of C++.
Indeed one of my worries was this : Either C does the actual
verification during run time which as I guess might use extra resources
which in turn could be used by the actual program or it might abandon
some of checks which renders the program in danger (not much surprising
for me though). Of course a solution by the help of auxiliary
tools,libraries,... but that is not standard routine anyway.
And at last (but not least as some say) thanks for the rich content.