Vadim said:
>
> [Wants to give a global variable the same identifier as
> a Standard library function]
The question is: is there any way to cancel a definition/declaration
made earlier, apart from opening a block and making a new definition
local in that block. My naive logic was, if it is possible for macros,
why not make a similar thing for regular C names.
Because macro identifiers have no linkage.
"Linkage" is the magic that takes an identifier that
appears in several different scopes and makes all those
different appearances refer to the same object or function:
/* file1.c */
int myValue = 42;
...
/* file2.c */
void func(void) {
extern int myValue;
...
}
Here we have two occurrences of the identifier `myValue'
each with its own scope. The scope of the first covers
all of file1.c from the point of declaration to the end.
The scope of the second is limited to the body of func();
the identifier is not "visible" outside the block.
But when the two files are combined into a single
program, both `myValue' identifiers are made to refer to
the same `int' variable. This process of coalescing
identically-named externally-linked identifiers into a
single entity is driven entirely by their names: If two
externally-linked identifiers have the same spelling, they
are combined to refer to the same object or function.
... which means that if you try to use the same
externally-linked name for two or more different things,
the association of "name" to "thing" breaks down. The
process of linking identifiers together depends on those
identifiers being unique[*], and if they aren't ... The
linker will have no way to resolve the conflict between
"different" identically-named identifiers, and Something
Bad will happen. (Some linkers will detect the problem,
some will detect it only in certain circumstances, and
some will not detect it at all but will give you a program
that doesn't do what you want.)
[*] For externally-linked identifiers there are even
stronger restrictions: Some linkers may consider only the
first N characters of an identifier, and some may treat
upper- and lower-case letters as identical. The details
of these additional restrictions depend on which Standard
("C89/90" or "C99") your implementation conforms to.