www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - betterC error?

reply makedgreatagain <patrick.kh7788 gmail.com> writes:
this very simple code can not build with betterC

void test(byte[] x){
	
}

extern(C) int main(string[] args){
       byte[] data = [0, 1];
	test(data);
	return 0;
}
Jun 12 2018
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 13/06/2018 12:13 AM, makedgreatagain wrote:
 this very simple code can not build with betterC
 
 void test(byte[] x){
 
 }
 
 extern(C) int main(string[] args){
        byte[] data = [0, 1];
      test(data);
      return 0;
 }
Well yes, dynamic arrays require the GC and hence TypeInfo. Slices don't, but that isn't a slice as it isn't from some random malloc'd memory.
Jun 12 2018
parent reply SrMordred <patric.dexheimer gmail.com> writes:
On Tuesday, 12 June 2018 at 12:29:17 UTC, rikki cattermole wrote:
 (...)
this line:
 byte[] data = [0, 1];
is an dynamic array allocated with GC. But if you declare as a static array like
byte[2] data = [0, 1];
than its not GC allocated.
Jun 12 2018
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 6/12/18 10:18 AM, SrMordred wrote:
 On Tuesday, 12 June 2018 at 12:29:17 UTC, rikki cattermole wrote:
 (...)
this line:
 byte[] data = [0, 1];
is an dynamic array allocated with GC. But if you declare as a static array like
 byte[2] data = [0, 1];
than its not GC allocated.
Or use C malloc. We really should provide better tools to create arrays using C malloc (for those who want them). Like a betterC toolkit. -Steve
Jun 12 2018
parent SrMordred <patric.dexheimer gmail.com> writes:
 Or use C malloc.

 We really should provide better tools to create arrays using C 
 malloc (for those who want them). Like a betterC toolkit.

 -Steve
Indeed, i´m creating my own "toolkit" for betterC stuff like alloc!Type(length); (much safer than malloc!) and other utilities :)
Jun 12 2018
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 6/12/2018 5:13 AM, makedgreatagain wrote:
 extern(C) int main(string[] args){
Need to declare main() like those C people do: extern (C) int main(int argc, char** argv){
Jun 12 2018
parent reply makedgreatagain <patrick.kh7788 gmail.com> writes:
On Tuesday, 12 June 2018 at 18:41:57 UTC, Walter Bright wrote:
 On 6/12/2018 5:13 AM, makedgreatagain wrote:
 extern(C) int main(string[] args){
Need to declare main() like those C people do: extern (C) int main(int argc, char** argv){
Thanks for all you help, the betteC is really useful and handy. I am try to made mobile app (right now IOS), seems Dan Olson 's great IOS work is stopped since 2 years ago. Hope the D community get better and better with more betterC Cross platform support.
Jun 12 2018
parent Walter Bright <newshound2 digitalmars.com> writes:
On 6/12/2018 7:31 PM, makedgreatagain wrote:
 Thanks for all you help, the betteC is really useful and handy.
That's great to hear!
Jun 12 2018