Ecere SDK/eC Forums http://ec-lang.org/community/ Print view |
|
[Solved]What's a comma and a semicolon http://ec-lang.org/community/viewtopic.php?f=1&t=164 |
Page 1 of 1 |
Author: | samsam598 [ Wed Aug 24, 2011 3:40 am ] |
Post subject: | [Solved]What's a comma and a semicolon |
Sorry I was a bit confused.Given below code Code: Select all
BWT,another question, Code: Select all
Thanks for the help. Regards, Sam |
Author: | jerome [ Wed Aug 24, 2011 3:59 am ] |
Post subject: | Re: What's a comma and a semicolon |
Comma/Semicolons: Within a class, a struct, or an instantiation, you can use commas or semicolons to separate members assignments. There can be extra semicolons, they won't hurt, but extra commas will cause syntax error. Before a function definition (or overriding virtual method), there must be a semicolon if there are any member assignments preceding it. There cannot be a comma left at the end, but there can be a semicolon at the end. After a class definition, it doesn't matter if you put a semi colon or not. After a struct definition, you must put a semicolon; To answer your first question about your example of q1 and q2, they are exactly the same. That date code is a little tricky. eC lets you write assignments as part of a class definitions, which kind of replaces the purpose of a constructor. But you cannot put statements there. So 'date = (now.GetLocalTime(), { now.year, now.month, now.day });' is a trick to embed a statement within an expression, so that we can assign it to our 'date' data member. The first part before the comma fills 'now' with the local time, and the part after the comma is the actual value of that whole expression within brackets, a 'Date' object that gets populated with the value in 'now'. The 'Date' struct is defined as such: Code: Select all
Other languages: liqi has been working (maybe still is ) on a Chinese localization of the whole SDK. We're trying to get it going using gettext. This could work for the Calendar Control as well Of course you could always write your own control the way you like. |
Author: | samsam598 [ Wed Aug 24, 2011 4:17 am ] |
Post subject: | Re: What's a comma and a semicolon |
Hi Jerome, Thank you so much for the detailed explanation. For the Date code example Code: Select all
date={now.year,now.month,now.day},or something like that? What's more,just realized this: Code: Select all
Thanks and regards, Sam |
Author: | jerome [ Wed Aug 24, 2011 11:46 am ] |
Post subject: | Re: What's a comma and a semicolon |
Hi Sam, date = (now.GetLocalTime(), { now.year, now.month, now.day }); Notice the parentheses, (not curly brackets). Parentheses in C/eC define an 'expression', a single value, in this case a 'Date' structure. Some info about this syntax on IBM's website. The first part before the comma is executed, discarded, and the value for the whole expression between ( ) is the second part where the { } are (where there are 3 data members, but it could be just { now.year, now.month } and day would be left to the default value of 0). Again, this is a just a trick to do it directly inside the class. You could instead write it in the constructor: Code: Select all
Because this is not a compound statement block inside a function, this is a class definition, where you are allowed to: 1. declare class members 2. assign default values for instances of the class to data members using assignment expressions I hope this makes things clearer |
Author: | samsam598 [ Wed Aug 24, 2011 7:37 pm ] |
Post subject: | Re: What's a comma and a semicolon |
Thanks Jerome,sorry for asking stupid questions to you. |
Author: | jerome [ Wed Aug 24, 2011 7:45 pm ] |
Post subject: | Re: What's a comma and a semicolon |
There are no stupid questions, only stupid answers |
All times are UTC-05:00 | Page 1 of 1 |
Powered by phpBB® Forum Software © phpBB Limited |