Re: Help me decide D or C

2019-08-02 Thread Alexandre via Digitalmars-d-learn
On Friday, 2 August 2019 at 15:51:25 UTC, Russel Winder wrote: On Fri, 2019-08-02 at 13:45 +, Alexandre via Digitalmars-d-learn wrote: […] Could you elaborate more about C being a burden? I have read so many people saying C gives a great foundation and should be everyone's

Re: Help me decide D or C

2019-08-02 Thread Alexandre via Digitalmars-d-learn
On Friday, 2 August 2019 at 12:30:44 UTC, berni wrote: On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: [...] In my oppinion C should have been deprecated about 50 years ago and it's not worth while to learn it if you are not interested in the history of programming or you have t

Re: Help me decide D or C

2019-08-01 Thread Alexandre via Digitalmars-d-learn
On Thursday, 1 August 2019 at 15:42:08 UTC, a11e99z wrote: On Thursday, 1 August 2019 at 15:17:11 UTC, a11e99z wrote: [...] imo better choice is (with criteria to find best job) - Qt: C++ with any library that u need in one style - C#: web, graphics, mobiles, command tools with nice la

Re: Help me decide D or C

2019-07-31 Thread Alexandre via Digitalmars-d-learn
On Wednesday, 31 July 2019 at 20:04:39 UTC, Ali Çehreli wrote: n 07/31/2019 12:05 PM, Paul Backus wrote: > I would not recommend D as a beginning language, both because there are > fewer beginner-oriented resources available for it than for C and Python > (the only one I know of is Ali Çehreli's

Re: Help me decide D or C

2019-07-31 Thread Alexandre via Digitalmars-d-learn
On Wednesday, 31 July 2019 at 22:16:42 UTC, bachmeier wrote: On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: [...] What is your goal? In my opinion, learning C is a waste of time in 2019 unless you have something specific in mind related to a job. C is mostly "fun with segmentat

Help me decide D or C

2019-07-31 Thread Alexandre via Digitalmars-d-learn
Hi everyone, I would like an honest opinion. I have a beginner level (able to do very small programs) in a few languages such as python, go, C, guile(scheme) and common lisp. I want to pick a language and go deep with it and focus on only one for at least the next 2 years or so. Should I go

Re: Any book recommendation for writing a compiler?

2017-11-01 Thread Alexandre via Digitalmars-d-learn
On Wednesday, 1 November 2017 at 20:56:22 UTC, Dr. Assembly wrote: On Wednesday, 1 November 2017 at 20:53:44 UTC, Dr. Assembly wrote: Hey guys, if I were to get into dmd's source code to play a little bit (just for fun, no commercial use at all), which books/resources do you recommend to start

Working with images

2017-11-01 Thread Alexandre via Digitalmars-d-learn
I have a project written in C++, that I'm thinking to migrating to D, but, what is preventing me from migrating to D, is the part of the system that works with images, where the system generates the image of a payment receipt, currently in the system written in C ++, there is an array with imag

Re: How to know whether a file's encoding is ansi or utf8?

2014-07-22 Thread Alexandre via Digitalmars-d-learn
http://www.architectshack.com/TextFileEncodingDetector.ashx On Tuesday, 22 July 2014 at 15:53:23 UTC, FreeSlave wrote: Note that BOMs are optional and may be not presented in Unicode file. Also presence of leading bytes which look BOM does not necessarily mean that file is encoded in some kind

Re: How to know whether a file's encoding is ansi or utf8?

2014-07-22 Thread Alexandre via Digitalmars-d-learn
Read the BOM ? module main; import std.stdio; enum Encoding { UTF7, UTF8, UTF32, Unicode, BigEndianUnicode, ASCII }; Encoding GetFileEncoding(string fileName) { import std.file; auto bom = cast(ubyte[]) read(fileName, 4);

Re: Binary IO

2014-07-18 Thread Alexandre via Digitalmars-d-learn
Maybe this can be usefull for u https://gist.github.com/bencz/3576dfc8a217a34c05a9 On Thursday, 17 July 2014 at 23:04:06 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Thu, Jul 17, 2014 at 09:01:35PM +, seany via Digitalmars-d-learn wrote: Data is a built in type? what includefile do I

Re: SImple C++ code to D

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Yes yes, I will use the ref... is more safer! I will try to re-create my logic... btw, how is the best way to "reinterpret" this ??: map syms; and: vector> values; vector>> addrs; On Tuesday, 15 July 2014 at 14:55:36 UTC, bearophile wrote: Alexandre: as rc is better for managing scarce resou

Re: SImple C++ code to D

2014-07-15 Thread Alexandre via Digitalmars-d-learn
I have this struct: enum AddrType { Abs, RVA, Rel }; struct Address { shared_ptr addr; AddrType type; Address(): type(Abs) {} Address(DWORD addr, AddrType type): addr(shared_ptr(new DWORD(addr))), type(type) {} Address(shared_ptr addr, AddrType type): addr(add

Re: SImple C++ code to D

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Oh! I used the RefCounted because this: "The proposed C++ shared_ptr<>, which implements ref counting, suffers from all these faults. I haven't seen a heads up benchmark of shared_ptr<> vs mark/sweep, but I wouldn't be surprised if shared_ptr<> turned out to be a significant loser in terms of

Re: String to int exception

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Strange..., why '@' ? PS: Ali Çehreli, thanks for your book, your book is wonderful!!! On Tuesday, 15 July 2014 at 13:49:51 UTC, Ali Çehreli wrote: On 07/15/2014 04:56 AM, Alexandre wrote: > retVal = to!int(val); > std.conv.ConvException@C:\D\dmd2\src\phobos\std\conv.d(1968): Unexpec

Re: String to int exception

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Something is wrong between our communication... I am wanting to do something better to order the bytes, for this my code... https://gist.github.com/bencz/3576dfc8a217a34c05a9 For example, in that case: injectData(image[0x207], x"30204000"); It's more simple to use something like: injectData(i

Re: String to int exception

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Thanks, but, when I convert I recive a 'c' in the front of my number... uint reverseBytes(uint val) { import core.bitop : bitswap; return bitswap(val); } //... writefln("%x", reverseBytes(0x00402030)); //... // output: c040200 On Tuesday, 15 July 2014 at 12:16:26 UTC, bearoph

String to int exception

2014-07-15 Thread Alexandre via Digitalmars-d-learn
Hi :) I made this function to inverse the bytes in intger or T (possible) type... int reverseBytes(T)(T val) { int retVal = 0; static if(is(T == string)) retVal = to!int(val); return (retVal & 0x00FF) << 24 | (retVal & 0xFF00)

Re: SImple C++ code to D

2014-07-14 Thread Alexandre via Digitalmars-d-learn
void InjectData(T)(ref T BaseSrc, string data) { memcpy(&BaseSrc, data.ptr, data.length); } It's possible to improve this function ? On Monday, 14 July 2014 at 15:45:19 UTC, bearophile wrote: Alexandre: Look the complete code: https://gist.github.com/bencz/3576dfc8a217a34c05a9 I kno

Re: SImple C++ code to D

2014-07-14 Thread Alexandre via Digitalmars-d-learn
Soory, I not understand, why lose the optlink ? Read the libs is simple, but, the linker do the brute force! On Monday, 14 July 2014 at 15:17:06 UTC, Jason King wrote: On Monday, 14 July 2014 at 14:50:36 UTC, Alexandre wrote: Yes yes, I did it, I used the anonymous type Look the complete code:

Re: SImple C++ code to D

2014-07-14 Thread Alexandre via Digitalmars-d-learn
Yes yes, I did it, I used the anonymous type Look the complete code: https://gist.github.com/bencz/3576dfc8a217a34c05a9 I know, has several things that can be improved

Re: SImple C++ code to D

2014-07-14 Thread Alexandre via Digitalmars-d-learn
bearophile, Thanks for all help! As I said, I'm coming from C # and C + +, I need to learn "tricks" of D language... 'm reading this book: http://ddili.org/ders/d.en/ I have a struct with union... struct IMAGE_SECTION_HEADER { BYTE[8] Name; union Misc {

Re: SImple C++ code to D

2014-07-14 Thread Alexandre via Digitalmars-d-learn
immutable ubyte[5] stub = x"b8 01 4c cd 21".representation; that is a Real-Mode Stub Program On Monday, 14 July 2014 at 12:32:38 UTC, Andrea Fontana wrote: Is there any counter-indication with this: immutable ubyte[5] stub = x"b8 01 4c cd 21".representation; ? Is it a compile time value?

Re: SImple C++ code to D

2014-07-14 Thread Alexandre via Digitalmars-d-learn
I don't see much need for such aliases. Ok, how I can reduce the number of aliaSs ? I suggest to avoid magic constants like that 0x80, like I have avoided it here: memcpy(&image[IMAGE_DOS_HEADER.sizeof], Btw, I need to start that part of code in x80 Look, that is my C++ code base: http://d

Re: SImple C++ code to D

2014-07-14 Thread Alexandre via Digitalmars-d-learn
And some other strange thing is, the generate struct in PE file is wrong.. look at imagens... As it should be...: http://i.imgur.com/4z1T3jF.png And how is being generated...: http://i.imgur.com/Oysokuh.png My actual source is that: http://dpaste.com/2TZKWF5 On Monday, 14 July 2014 at 11:55:1

Re: SImple C++ code to D

2014-07-14 Thread Alexandre via Digitalmars-d-learn
Look at line 114 of my code: http://dpaste.com/3B5WYGV Have a more better way to make this conversion ? *(DWORD*)"PE\0\0" ?

Re: SImple C++ code to D

2014-07-13 Thread Alexandre via Digitalmars-d-learn
Oh, thanks a lot!! With a little change all work! look: struct IMAGE_DOS_HEADER { WORD e_magic, e_cblp, //... void main() { import std.stdio; import std.file; import core.stdc.string; auto dosh = cast(PIMAGE_DOS_HEADER)image.ptr;

Re: SImple C++ code to D

2014-07-13 Thread Alexandre via Digitalmars-d-learn
Ok, thanks thanks!!! Have a lot of thinks I need to learn When I generate the exe file, something is wrong with this: dosh.e_magic = cast(WORD)*"MZ".ptr; When the PE file is generate in EXE have just the "M" of "MZ"...

SImple C++ code to D

2014-07-13 Thread Alexandre via Digitalmars-d-learn
I have this code in C++ //... char image[0x800]; //... auto dosh = reinterpret_cast(&image[0]); dosh->e_magic = *(WORD*)"MZ"; dosh->e_cblp = 0x90; dosh->e_cp = 3; dosh->e_cparhdr = 4; dosh->e_maxalloc = 0x; dosh->e_sp = 0xb8; dosh->e_lfarlc = 0x40; dosh

Re: Insert a char in string

2014-07-10 Thread Alexandre via Digitalmars-d-learn
basically format I read a cobol struct file... From pos X to Y I have a money value... but, this value don't have any format.. 0041415 The 15 is the cents... bascally I need to put the ( comma ), we use comma to separate the cents, here in Brazil... On Thursday, 10 July 2014 at

Sum a lot of numbers...

2014-07-10 Thread Alexandre via Digitalmars-d-learn
Hi :) I need to sum a list of numbers... but, when I calculate the sum of this numbers, I got a simplify representation of sum: 2.97506e+,12 How I can make to get the correctly representation of this number ?

Re: Sum a lot of numbers...

2014-07-10 Thread Alexandre via Digitalmars-d-learn
PS: that is my code: import std.stdio, std.algorithm, std.range, std.conv; string InsertComma(string val) { return val[0 .. $-2] ~ "," ~ val[$-2 .. $]; } int main(string[] argv) { auto x = "oi.txt" .File .byLine .filter!(line => li

Re: Insert a char in string

2014-07-10 Thread Alexandre via Digitalmars-d-learn
Oh, I used that letters in upper case, just for a simple sample... On Thursday, 10 July 2014 at 16:32:53 UTC, Marc Schütz wrote: On Thursday, 10 July 2014 at 16:20:29 UTC, Alexandre wrote: Sorry.. I mean: auto X = "100"; auto N = X.insertInPlace(3,','); On Thursday, 10 July 2014 a

Re: Insert a char in string

2014-07-10 Thread Alexandre via Digitalmars-d-learn
I used that solution: string InsertComma(string val) { return val[0 .. $-2] ~ "," ~ val[$-2 .. $]; } On Thursday, 10 July 2014 at 16:23:44 UTC, John Colvin wrote: On Thursday, 10 July 2014 at 16:05:51 UTC, Alexandre wrote: I have a string X and I need to insert a char in that string...

Re: Insert a char in string

2014-07-10 Thread Alexandre via Digitalmars-d-learn
Sorry.. I mean: auto X = "100"; auto N = X.insertInPlace(3,','); On Thursday, 10 July 2014 at 16:05:51 UTC, Alexandre wrote: I have a string X and I need to insert a char in that string... auto X = "100"; And I need to inser a ',' in position 3 of this string..., I tr

Insert a char in string

2014-07-10 Thread Alexandre via Digitalmars-d-learn
I have a string X and I need to insert a char in that string... auto X = "100"; And I need to inser a ',' in position 3 of this string..., I try to use the array.insertInPlace, but, not work... I try this: auto X = "100"; auto N = X.insertInPlace(1,'0');

Re: Sum informations in file....

2014-07-10 Thread Alexandre via Digitalmars-d-learn
O, real intresting the mode functional style!!! Like linq! hahah Btw, it's work very well, thansk!!! But, how I can insert an ',' comma to separe the decimal place ? ( the last 2 digits ) I can't find a "insert" instruction in std.string or std.array On Thursday, 10 July 2014 at 15:01:52 U

Sum informations in file....

2014-07-10 Thread Alexandre via Digitalmars-d-learn
I have one file with a lot of numeric data... and I need to sum all that data... That is my actual code: module main; import std.stdio; import std.file; import std.conv : to; int main(string[] args) { auto f = File("oi.txt"); auto r = f.byLine(); auto tot = 0;