Enum again

1 view
Skip to first unread message

Sam Hu

unread,
Sep 17, 2008, 11:06:42 PM9/17/08
to eC Programming Language
Hi Jerome,

I re-test the enum examples again and below is the source based on the
Dao,please refer to the comments in the source after //:

BTW,how can it print the enum value to it rep. ,say in this
example,output "star is earth",this is really wonderful!

//**********************
enum Planet
{
mercury,venus,earth,mars,jupiter,sturn,uranus,neptune
};
enum PlanetOrDwarfPlanet:Planet
{
ceres,pluto,eris
};
class App:Application
{
void Main()
{
int val,size;
Planet star;
PlanetOrDwarfPlanet planet1,planet2 ;

star=earth;
PrintLn("star is " ,star);//ouput:star is earth--wow!!

val=star;
PrintLn("val is ",val);

size=Planet::enumSize;
PrintLn("size=",size);

planet1=mercury;//compiling warning message:warning:
incompatible expression 0 (Planet);expected PlanetOrDwarfPlanet
PrintLn("planet1=",planet1);//output :planet1=Ceres,WRONG!!!

planet2=pluto;
PrintLn("planet2=",planet2);

size=PlanetOrDwarfPlanet::enumSize;
PrintLn("size of PlanetOrDwarfPlanet=",size);//output:size
of ,,,=3,WRONG!!

system("PAUSE");

}
}
//****************************

Jerome St-Louis

unread,
Sep 17, 2008, 11:45:54 PM9/17/08
to ec-programm...@googlegroups.com
Hi Sam,

This enum inheritance (continuity) functionality is broken at the moment.

I thought an issue was already in Mantis, but I couldn't find any.
So I created this new issue http://www.ecere.com/mantis/view.php?id=139

I will make sure to fix this for the next release.

Please keep in mind the Tao is still work in progress, and sometimes it might be more correct than the current compiling tools =)

Thanks,

Jerome

Sam Hu

unread,
Sep 18, 2008, 12:11:00 AM9/18/08
to eC Programming Language
Hi jerome,

Well noted.Also please note that below code does not work also:

double planetsRadii[Planet];
int* pointer=planetsRadii;
planetsRadii[jupiter]=71492;

PrintLn("the fifth element of planetsRadii using pointer is
",pointer[Planet::jupiter]);//line 1
PrintLn("the fifth element of planetsRadii using pointer is
",&pointer[Planet::jupiter]);//line 2
printf("the fifth element of planetsRadii is %d
\n",pointer[4]); //line 3

Above three lines both PrintLn & printf prints 45485556

Regards,
Sam

Jerome St-Louis

unread,
Sep 18, 2008, 12:18:24 AM9/18/08
to ec-programm...@googlegroups.com
Hi Sam,

planetsRadii is an array of double, you need to use a double pointer, not an int pointer

( double * pointer=planetsRadii; )

Also, printf 's %d specifier is strictly for integer values, you need to use %f or %lf for double.

Your second (middle) PrintLn prints out the address of the pointer element, not the contents of the element, so don't expect it to print out 71492.

Jerome

Sam Hu

unread,
Sep 18, 2008, 2:26:21 AM9/18/08
to eC Programming Language
Hi Jerome,

1,I revised as below,now all the 7 lines of PrintLn prints 71492.
//************************
int planetRadii[Planet];
int* pointer=null;

planetsRadii[jupiter]=71492;

PrintLn("the fifth element of planetsRadii using pointer is
",pointer[Planet::jupiter]);
PrintLn("the fifth elements of planetsRadii using & is
",&pointer[Planet::jupiter]);
PrintLn("the fifth elements of planetsRadii using & with array
Name is",
&planetsRadii[4]);
PrintLn("The fifth elements of planetsRadii using & with array
Name and enum index is",
&planetsRadii[Planet::jupiter]);
PrintLn("The fifth elements of planetsRadii is
",planetsRadii[4]);
PrintLn("the fifth element of planetsRadii is ",pointer[4]);
PrintLn("the fifth element of planetsRadii is ",*(pointer
+4));

//****************************************
2.As we have discussed in previous thread,that a struct passed in the
function with a struct key word will make the struct parm passed by
value other than by reference.Say,

//*****************
struct InventoryItem
{
int code;
float price;


} ;

void print(InventoryItem item)
{
PrintLn("item.code= %d\nitem.price=%.2f\n",item.code,item.price);
}


void DontModifyItem(struct InventoryItem item)
{
item.code=1234;
item.price=45.0f;
}
void Test()
{
InventoryItem item1{};
DontModifyItem(item1);
Print(item1);
//***********************
This can not pass the compiler:
structApp.ec:17: error: invalid type argument of '->' (have 'struct
InventoryItem')
structApp.ec:18: error: invalid type argument of '->' (have 'struct
InventoryItem')
structApp.ec:23: error: incompatible type for argument 1 of
'DontModifyItem'

Hope this problem can be fixed very soon.
Regards,
Sam

Jerome St-Louis

unread,
Sep 18, 2008, 12:56:31 PM9/18/08
to ec-programm...@googlegroups.com
Thanks Sam.
I created an issue on mantis for this: http://www.ecere.com/mantis/view.php?id=140

Jerome
Reply all
Reply to author
Forward
0 new messages