Re: How to convert Infix notation to postfix notation



(READER NOTE: There is actual content about C in this one, just for variety.)

On 2009-11-06, spinoza1111 <spinoza1111@xxxxxxxxx> wrote:
This is
of course that

(1) Functions must be defined before use (an idiot language feature
since it is an artifact of the thrilling days of yesteryear when
storage was limited, and programs were on paper tape and could not,
conveniently, be read more than once)

You're gonna have to work harder on learning the terminology if you want
to discuss C and not just be laughed at.

Functions must be *declared* before use. The thing with a function body
is a definition, the one without a function body is a declaration, also
called a prototype.

You also don't understand the intent or purpose of the feature. You're
unlikely to even if it's explained, because you seem to have attained
a nearly supernatural level of willful blindness to even the most trivial
facts, but we have other readers.

Q: Why doesn't C just read the whole file to find a function's definition?

A: Because prototypes would be needed anyway.

C is designed to support genuinely modular code -- you can build a program
which incorporates functionality that was previously compiled. That means
that you can, on nearly all implementations, build a program which includes
pieces of code for which you have *no source code*. The solution adopted
in early C was to allow declarations of external functions which are used
to generate code to call those functions even if no definition for that
function exists in source code. In C89, this feature was extended (based
in part, as I recall, on the C++ prototype feature) to include "prototypes"
which provide declarations of the arguments, not just the return types,
of the function.

Prototypes are primarily used to address the fairly common case where the
function being called is defined in a separate "translation unit" (in most
cases, this means "source file", but there are technical differences).

At the time, it made sense to allow compilers to continue to, at least in
principle, be able to operate in a single pass. While that's less crucial
now perhaps than it used to be (as most modern optimizers end up needing
to work with everything in memory for a while), it's still considered a
plus for vendors targeting smaller systems. (In a fit of irony, Microsoft
systems were one of the targets that benefitted a lot from this, but of
course, they're not important.)

Since prototypes are already needed, and well-defined, the language just
expects you to provide them whenever you call a function before its
definition.

(2) Fixing this problem (which is an iinsult to the intelligence)

In normal English, "an insult to the intelligence" isn't supposed to be
a precise synonym for "which is reasonable for reasons I don't understand",
but I guess I've gotten used to your diaect.

in the ordinary way means coding the declaration twice.

Or using functions only after their definition.

If you know a better way to fix the problem, what is it?

The canonical solution is, in fact, to declare the function once and
define it once, usually with the declaration in a header if it's going
to be used by or seen by other translation units.

My way gives a nice little overview and is reasonably easy to
maintain.

The regular way is pretty easy to maintain if your prototypes don't change
too often, and if they change too often, they're changing too often.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam@xxxxxxxxx
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
.



Relevant Pages

  • Re: How to convert Infix notation to postfix notation
    ... is a definition, the one without a function body is a declaration, also ... There's no real need these days for function prototypes, for functions which are defined in the same file at least. ... plus for vendors targeting smaller systems. ... How many development computers these days are only capable of running a single-pass compiler? ...
    (comp.lang.c)
  • Re: How to convert Infix notation to postfix notation
    ... is a definition, the one without a function body is a declaration, also ... You also don't understand the intent or purpose of the feature. ... Prototypes are primarily used to address the fairly common case where the ... You need to actually learn a radically different programming language. ...
    (comp.lang.c)
  • Re: Is this necessary?
    ... These are called function prototypes, which are a kind of declaration ... In versions of C prior to the 1999 language standard update, ... which was that it must have a return type of int. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: ping source code
    ... >I was reading through original source code of ping for some insight ... and types (defaulting to int if not specified) given between the ... the older type of declaration; I'm not sure about C99 - implicit int is ...
    (comp.lang.c)
  • Re: why still use C?
    ... This touches on an interesting notational point with regard to C++ ... source code of the declaration of the class. ... Java, where declaration and definition coincide. ...
    (comp.lang.c)