www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - One more purpose for -cstyle

In the D.learn nesgroup Heywood Floyd has started a short thread about 2D
arrays definition, he finds them confusing, and he currently wants to use the
int marr[3][5]; syntax.

It's not good to have two different syntaxes to define arrays in a language,
but I too have found the C-style syntax useful when I have translated some C
code to D (later I have replaced the C definitions with D ones).

Recently I have suggested a compilation switch like:
-cstyle
designed to help porting of C code to D that warns against:
- usage of global floating point variables/arrays that in some C programs are
used with not initialization, assuming they are set to zero (while D
initializes them to NaN), this has caused a slow to find bug in one of my
programs;
- A warning against the usage of large fixed-sized arrays, that are passed
around by reference in C and by value in D, so if they are large the program
can get slower in D. (I think D already guards against some C-style arrays
usages that exploit the reference nature of array arguments).

To those two purposes of the -cstyle compiler switch a third can be added: to
allow the C-style array definition syntax. So unless -cstyle is used then
int marr[3][5];
is a syntax error.
This allows to keep the purpose of C-style array definitions (for porting from
C code) while essentially making it deprecated for normal D programs.

Bye,
bearophile
Jul 12 2010