I spent ALL day playing with named parameters instead of positional
parameters to functions, and ended up throwing it all away. C just
doesn't make that easy or clean.
But the basic gist of what I want, is this: I would like to create a
'data dictionary' that stores the data name and type. Whenever I need
a new function parameter or local variable, and it's manipulating an
item that is described in the data dictionary, I want to be able to
declare and use it without thought... I don't want to have to remember
or look up what type it is.
I have some sample code to show you. It's pretty short, which is
funny, considering all the complicated stuff I threw away earlier
today. >:-D But simple is good - maybe that means it will be easier to
use.
#include<stdio.h>
#include<memory.h>
#define ID __int64
#define AGE int
#define HEIGHT int
#define NAME char*
void Test(ID id, NAME name, AGE age, HEIGHT height)
{
printf("ID %I64d, Name %s, Age %d, Height %d\n", id, name, age,
height);
}
void main()
{
ID id = 64;
NAME name = "Sandy";
Test(id, name, 99, 145);
}
Does anyone have any thoughts about using this method?
Here's a couple of my thoughts:
1. I hate typedefs. I've shot myself in the foot once with them, stared
at the gory hole for a few minutes, and decided I was never gonna use
them if there was an alternative. This method doesn't use typedefs.
2. The decision on what to call a variable becomes easy. Look up the
variable in the data dictionary, use the uppercase version for the type,
the lowercase version for the variable.
3. It will help in the declaration of structures, as well... no more
hunting around for all references to a member (parameters, members,
etc.) when you change the type.
4. There is a possibility of collision with other uppercase constants
and such, but it doesn't look to be too difficult.
5. Being a #define instead of a table lookup, it doesn't slow down the
code or add to the memory requirements.
If there's something wrong with it, let me know!
If it's all good, yay. :-)
--Kami