[comp.lang.c] how do I declare a constant as a variable of different type

mouse@thunder.mcrcim.mcgill.edu (der Mouse) (05/24/91)

In article <16452@helios.TAMU.EDU>, n077gh@tamuts.tamu.edu (Sharma Anupindi) writes:

> I read a string ( which is unknown prior to readig ) into character
> variable.
> like:
> 	char name[30];
> 	fsacnf(fp,"%s",name);
> Now I want to declare the string I have read from the file as a
> different variable.

This is really a C question, not a UNIX question.  I'm cross-posting to
comp.lang.c and pointing followups there.

This really doesn't make sense to do.  Variable names don't exist at
run-time[%]; only the variables themselves do.  Variable names are a
compile-time thing.  You are trying to do a compile-time thing at
run-time.

It wouldn't be much use in any case, because you couldn't use the
resulting variable without a facility for accessing it given a string
containing the name.  And if *that*'s what you want to do, you can, but
you have to allocate and maintain the space for the variable, and the
data structures to map between names and storage places, yourself.
(Something rather like this is what languages like Lisp, that let you
do run-time variable creation, do internally.)

[%] Yes, I know about the symbol table.  It may not exist, if it does
    it may not be accessible, and in any case it has no bearing on
    declaring new variables.

> Ex:
> If my file contains the string "Mr.Brilliant", then name will contain
> the same string.
> Now I want to declare "Mr.Brilliant" as a integer, for further use in
> the program.

This is actually a telling example.  Mr.Brilliant is not a legal
variable name; . cannot appear in C symbols.  (For this to be legal
where a variable is expected, Mr would have to be an instance of a
structure containing a member called Brilliant.)

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu