Opened 16 years ago
Closed 15 years ago
#249 closed task (fixed)
Change signature of main to be consistent with C
| Reported by: | zirkel | Owned by: | Stephen Siegel |
|---|---|---|---|
| Priority: | major | Milestone: | 1.1 |
| Component: | examples | Version: | 1.1 |
| Keywords: | Cc: |
Description
Need to change from:
void main()
to
int main(int argc, char**argv)
Change History (5)
comment:1 by , 16 years ago
| Milestone: | Release 1.0 → 1.1 |
|---|---|
| Version: | → 1.1 |
comment:2 by , 16 years ago
How about: if any arguments to main are given, they are just counted as additional input variables.
If a non-void output type is declared, it is considered one more output variable.
The comparator will have to check that the two main functions have the same signatures.
comment:3 by , 16 years ago
| Owner: | set to |
|---|---|
| Status: | new → accepted |
Here is my proposed solution:
- the main function for a process can take any kinds of arguments (inputs) and return any kind of output
- the input signatures for the main functions of all processes in a model must agree
- only the returned value from the main function of process 0 will be used. the returned value from the main functions of other processes will be ignored. In particular, the return types do not have to agree, since they will only be used on process 0. (Rationale: it isn't clear what to do with the returned values of mains on other processes. You cannot use them to do a process-by-process comparison in compare mode because the two programs being compared do not necessarily have the same number of processes. You could check that every process returns the same value, but is that really what one expects to happen?)
- execution semantics: new input variables will automatically be added to the model to correspond to the arguments to main. When the process is initialized, main will be invoked with the arguments being assigned the values of those input variables. One output variable will also be added to the model if the return type of main is non-void. When process 0 terminates normally (by main returning), the value returned will be stored in the output variable. When other processes return, the value returned will just be thrown away.
- comparison: for two programs to be comparable, the main methods must have the same input signatures. Also, the main methods on process 0 must have the same output type. The two programs are then compared in the usual way. If the two process 0s return different values, an error is reported.
comment:4 by , 15 years ago
The problem is there is no ragged array value type, which is what you want to represent the input strings, as each string is an array of char of different lengths.
A compromise solution for now is to have the user specify the number of args (argc) at the command line (-argc=3). Then an explicit input variable pair could be created for each arg: int TASS_arglength_0, char TASS_arg[TASS_arglenth_0], ...
comment:5 by , 15 years ago
| Resolution: | → fixed |
|---|---|
| Status: | accepted → closed |
Implemented ragged arrays. C-style main function adds appropriate input variables and output variable. See comments in ModelIF and method processMainFunction() in Model. A simple example has been added.

Maybe some flexibility should be allowed here: both (or other forms) should be allowed.