Re: "strtok" D equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 23:16:15 UTC, Paul Backus wrote:

On Thursday, 28 July 2022 at 21:52:28 UTC, pascal111 wrote:

On Thursday, 28 July 2022 at 20:36:31 UTC, Paul Backus wrote:

```d
import std.algorithm: filter;
import std.range: empty;
import std.functional: not;

// ...

auto tokens = input
.splitter!(c => delimiters.canFind(c))
.filter!(not!empty);

// ...
```


I think "tokens" is a range. I didn't read much about it, but 
I figured out that there's no particular way to know the 
number of elements in a range, or how can you know the 
elements order and the length of the range?


In this case, the only way is to convert the range to an array, 
using [`std.array.array`][1]:


```d
import std.array: array;

// ...

string[] tokens = input
.splitter!(c => delimiters.canFind(c))
.filter!(not!empty)
.array;
```

[1]: https://phobos.dpldocs.info/std.array.array.1.html


This is the first program using "d_strtok":
https://github.com/pascal111-fra/D/blob/main/proj03.d

This is the "dcollect" module:
https://github.com/pascal111-fra/D/blob/main/dcollect.d


Re: "strtok" D equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 23:16:15 UTC, Paul Backus wrote:

On Thursday, 28 July 2022 at 21:52:28 UTC, pascal111 wrote:

On Thursday, 28 July 2022 at 20:36:31 UTC, Paul Backus wrote:

```d
import std.algorithm: filter;
import std.range: empty;
import std.functional: not;

// ...

auto tokens = input
.splitter!(c => delimiters.canFind(c))
.filter!(not!empty);

// ...
```


I think "tokens" is a range. I didn't read much about it, but 
I figured out that there's no particular way to know the 
number of elements in a range, or how can you know the 
elements order and the length of the range?


In this case, the only way is to convert the range to an array, 
using [`std.array.array`][1]:


```d
import std.array: array;

// ...

string[] tokens = input
.splitter!(c => delimiters.canFind(c))
.filter!(not!empty)
.array;
```

[1]: https://phobos.dpldocs.info/std.array.array.1.html


What about this version:

string[] d_strtok(const string ch, const string delim)
{

string[] tokens = ch.
splitter!(c => delim.canFind(c)).
filter!(not!empty).array;

return tokens;
}





module main;

import std.stdio;
import std.string;
import std.conv;
import dcollect;
import std.math;
/*import std.algorithm;
import std.range: empty;
import std.functional: not;
import std.array;*/

int main(string[] args)
{

string bad_guy="This is,, an, statement.";
string[] coco=d_strtok(bad_guy, " ,.");

for(int i=0; iReally I don't understand all of its code well although it works 
fine.


Re: "strtok" D equivalent

2022-07-28 Thread Paul Backus via Digitalmars-d-learn

On Thursday, 28 July 2022 at 21:52:28 UTC, pascal111 wrote:

On Thursday, 28 July 2022 at 20:36:31 UTC, Paul Backus wrote:

```d
import std.algorithm: filter;
import std.range: empty;
import std.functional: not;

// ...

auto tokens = input
.splitter!(c => delimiters.canFind(c))
.filter!(not!empty);

// ...
```


I think "tokens" is a range. I didn't read much about it, but I 
figured out that there's no particular way to know the number 
of elements in a range, or how can you know the elements order 
and the length of the range?


In this case, the only way is to convert the range to an array, 
using [`std.array.array`][1]:


```d
import std.array: array;

// ...

string[] tokens = input
.splitter!(c => delimiters.canFind(c))
.filter!(not!empty)
.array;
```

[1]: https://phobos.dpldocs.info/std.array.array.1.html


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread frame via Digitalmars-d-learn

On Thursday, 28 July 2022 at 20:20:27 UTC, pascal111 wrote:

I retyped again some function of C library I made before, but 
with D code:


It's a start but you need to learn.

- these functions can run into UB if you compile it without bound 
checking enabled


- when working with arrays or ranges it's better to use unsigned 
integers or just use `size_t` which represents unsigned integer 
for 32 or 64 bit. This avoids negative values and enables the 
maxmium value which can be provided on the plattform to access 
the highest element in the array.


- It's sure advanced topic but you should start to check your 
input from the beginning. Try what happens if you apply negative 
numbers or invalid offsets ;-)


I don't know which client you are using but please have an eye on 
proper format of your posts - see the "Markdown formatting" or 
disable the Markdown option below your input.


https://forum.dlang.org/help#about




Re: "strtok" D equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 20:36:31 UTC, Paul Backus wrote:

On Thursday, 28 July 2022 at 19:17:26 UTC, pascal111 wrote:

What's the "strtok" - C function - D equivalent?

https://en.cppreference.com/w/cpp/string/byte/strtok


Closest thing is probably `std.algorithm.splitter` with a 
predicate:


```d
import std.algorithm: splitter, canFind;
import std.stdio;

void main()
{
string input = "one + two * (three - four)!";
string delimiters = "! +- (*)";
auto tokens = input.splitter!(c => delimiters.canFind(c));
foreach (token; tokens) {
writef("\"%s\" ", token);
}
}
```

Output:

```
"one" "" "" "two" "" "" "" "three" "" "" "four" "" ""
```

Unlike `strtok`, this code does not skip over sequences of 
multiple consecutive delimiters, so you end up with a bunch of 
empty tokens in the output. To exclude them, you can use 
`std.algorithm.filter`:


```d
import std.algorithm: filter;
import std.range: empty;
import std.functional: not;

// ...

auto tokens = input
.splitter!(c => delimiters.canFind(c))
.filter!(not!empty);

// ...
```


I think "tokens" is a range. I didn't read much about it, but I 
figured out that there's no particular way to know the number of 
elements in a range, or how can you know the elements order and 
the length of the range?


Re: "strtok" D equivalent

2022-07-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 28, 2022 at 09:03:55PM +, pascal111 via Digitalmars-d-learn 
wrote:
> On Thursday, 28 July 2022 at 19:37:31 UTC, rikki cattermole wrote:
[...]
> > foreach(value; input.splitWhen!((a, b) => delimiters.canFind(b))) {
> > writeln(value);
> > }
> > }
> > ```
> 
> From where can I get details about properties like "canFind" and
> "splitWhen" or other properties. The next link has mentioning for more
> properties:
> 
> https://dlang.org/spec/arrays.html

These are not properties; these are function calls using UFCS (Uniform
Function Call Syntax).  In a nutshell, whenever the compiler sees
function call of the form:

object.funcName(args);

but `object` does not have a member function named `funcName`, then the
compiler will rewrite it instead to:

funcName(object, args);

So, if you have a function that takes a string as a 1st argument, let's
say:

string myStringOp(string s) { ... }

then you can write:

"abc".myStringOp();

instead of:

myStringOp("abc");

This in itself may seem like a rather inane syntactic hack, but the
swapping of function name and first argument allows you to chain several
nested function calls together while keeping the calling order the same
as the visual order:

// What does this do?? You have to scan back and forth to figure
// out what is nested in what.  Hard to read.
writeln(walkLength(filter!(l => l > 3)(map!(e => e.length),
["a", "abc", "def", "ghij"])));

can be rewritten using UFCS in the more readable form:

// Much easier to read: take an array, map each element to
// length, filter by some predicate, and count the number of
// matches.
writeln(["a", "abc", "def", "ghij"]
.map!(e => e.length)
.filter!(l => l > 3)
.walkLength);

The identifiers splitWhen and canFind in the original code snippet are
Phobos library functions. Pretty much all of the functions in
std.algorithm, std.range, std.array, and std.string can be used in this
manner.


T

-- 
People walk. Computers run.


Re: "strtok" D equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 19:37:31 UTC, rikki cattermole wrote:
I don't know of a D version, although it should be pretty easy 
to write up yourself.


But you can always use strtok itself.

https://github.com/dlang/dmd/blob/09d04945bdbc0cba36f7bb1e19d5bd009d4b0ff2/druntime/src/core/stdc/string.d#L97

Very similar to example given on the docs:

```d
void main()
{
import std.stdio, std.algorithm;
string input = "one + two * (three - four)!";
string delimiters = "!+-(*)";

foreach(value; input.splitWhen!((a, b) => 
delimiters.canFind(b))) {

writeln(value);
}
}
```


From where can I get details about properties like "canFind" and 
"splitWhen" or other properties. The next link has mentioning for 
more properties:


https://dlang.org/spec/arrays.html


Re: Build for i586

2022-07-28 Thread dd via Digitalmars-d-learn

On Thursday, 28 July 2022 at 06:01:17 UTC, Alexander Zhirov wrote:

I'm at a dead end, please help, guys.


1. Can you try with `ldc2 --march=32bit-mode`? The march list 
(--march=help) details this as "32-bit mode (80386)".


2. Can you try with `ldc2 --march=i586 -betterC` with a simple 
BetterC program? (Like `import core.stdc.stdio; extern(C) void 
main() { puts("test");}`)


3. Otherwise, can you try checking which instruction is illegal 
under a debugger? The i686 introduced the CMOVcc instruction 
which I think both compilers emit regardless of march (Default 
target: i686-pc-linux-gnu), since I think it's the default 
baseline, but I could be wrong.


Re: "strtok" D equivalent

2022-07-28 Thread Paul Backus via Digitalmars-d-learn

On Thursday, 28 July 2022 at 19:17:26 UTC, pascal111 wrote:

What's the "strtok" - C function - D equivalent?

https://en.cppreference.com/w/cpp/string/byte/strtok


Closest thing is probably `std.algorithm.splitter` with a 
predicate:


```d
import std.algorithm: splitter, canFind;
import std.stdio;

void main()
{
string input = "one + two * (three - four)!";
string delimiters = "! +- (*)";
auto tokens = input.splitter!(c => delimiters.canFind(c));
foreach (token; tokens) {
writef("\"%s\" ", token);
}
}
```

Output:

```
"one" "" "" "two" "" "" "" "three" "" "" "four" "" ""
```

Unlike `strtok`, this code does not skip over sequences of 
multiple consecutive delimiters, so you end up with a bunch of 
empty tokens in the output. To exclude them, you can use 
`std.algorithm.filter`:


```d
import std.algorithm: filter;
import std.range: empty;
import std.functional: not;

// ...

auto tokens = input
.splitter!(c => delimiters.canFind(c))
.filter!(not!empty);

// ...
```


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 17:46:49 UTC, frame wrote:

On Thursday, 28 July 2022 at 16:45:55 UTC, pascal111 wrote:

Aha! "In theory, someone could inject bad code", you admit my 
theory.


The code would need to work and pass merge tests too. The merge 
reason must match in review. If someone fixes a task and 
additionally adds 100 LOC some should, will ask what this is 
about.


It's a extrem unlikely scenario. You may heard of linux kernel 
source that contains code that no one exactly knows about. But 
this some kind of bait. It's old code, reviewed years ago, not 
needed anymore but not knowing to be harmful. Completely 
different.


Anyway, code old or new may be harmful if it allows UB 
(undefined behaviour) and that is what hackers primarily use, 
not secret backdoors. This is why it's important to write 
CORRECT software that doesn't allow and cannot fall in a state 
of UB.


I agree with you in some points.

I retyped again some function of C library I made before, but 
with D code:



module dcollect;

import std.stdio;
import std.conv;
import std.ascii;

//

string strleft(const string ch, int n)
{

string ch_sub;

ch_sub=ch[0..n];

return ch_sub;

}

//

string strreverse(const string ch)
{

string ch_rev;

for(int i=to!int(ch.length-1); i>=0; i--)
ch_rev~=ch[i];


return ch_rev;


}

/*/

string strright(const string ch, int n)
{

string ch_sub1,
ch_sub2;

ch_sub1=strreverse(ch);

ch_sub2=strleft(ch_sub1, n);

ch_sub1=strreverse(ch_sub2);

return ch_sub1;

}

/*/

string strmid(const string ch, int x, int l)
{

string ch_sub;

ch_sub=ch[x..(x+l)];

return ch_sub;

}

/*/

string strtolower(const string ch)
{

string ch_cpy;

for(int i=0; i

Re: "strtok" D equivalent

2022-07-28 Thread rikki cattermole via Digitalmars-d-learn
I don't know of a D version, although it should be pretty easy to write 
up yourself.


But you can always use strtok itself.

https://github.com/dlang/dmd/blob/09d04945bdbc0cba36f7bb1e19d5bd009d4b0ff2/druntime/src/core/stdc/string.d#L97

Very similar to example given on the docs:

```d
void main()
{
import std.stdio, std.algorithm;
string input = "one + two * (three - four)!";
string delimiters = "!+-(*)";

foreach(value; input.splitWhen!((a, b) => delimiters.canFind(b))) {
writeln(value);
}
}
```


"strtok" D equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn

What's the "strtok" - C function - D equivalent?

https://en.cppreference.com/w/cpp/string/byte/strtok


Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 16:03:46 UTC, Alexander Zhirov wrote:
[...]

How did you manage to get hold of this compiler?

```
/root/usr/program/gcc/9.5.0/install/bin/cc
```


Where does this compiler come from?


This is an unpacked archive from an official source from the 
GNU website


https://ftp.mpi-inf.mpg.de/mirrors/gnu/mirror/gcc.gnu.org/pub/gcc/releases/gcc-9.5.0/


The archive `gcc-9.5.0.tar.gz` I found in that directory does not 
contain any binary compiler. The only "file" named "cc" is the 
directory


```
./gcc/testsuite/ada/acats/tests/cc
```


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread frame via Digitalmars-d-learn

On Thursday, 28 July 2022 at 16:45:55 UTC, pascal111 wrote:

Aha! "In theory, someone could inject bad code", you admit my 
theory.


The code would need to work and pass merge tests too. The merge 
reason must match in review. If someone fixes a task and 
additionally adds 100 LOC some should, will ask what this is 
about.


It's a extrem unlikely scenario. You may heard of linux kernel 
source that contains code that no one exactly knows about. But 
this some kind of bait. It's old code, reviewed years ago, not 
needed anymore but not knowing to be harmful. Completely 
different.


Anyway, code old or new may be harmful if it allows UB (undefined 
behaviour) and that is what hackers primarily use, not secret 
backdoors. This is why it's important to write CORRECT software 
that doesn't allow and cannot fall in a state of UB.


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 17:21:57 UTC, H. S. Teoh wrote:
On Thu, Jul 28, 2022 at 04:45:55PM +, pascal111 via 
Digitalmars-d-learn wrote:

[...]


In theory, Ken Thompson's compromised compiler hack could be at 
work[1].


[...]


I think you say advanced technical information. My information is 
not at that level.


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 28, 2022 at 04:45:55PM +, pascal111 via Digitalmars-d-learn 
wrote:
> On Thursday, 28 July 2022 at 16:37:35 UTC, frame wrote:
> > On Thursday, 28 July 2022 at 16:17:16 UTC, pascal111 wrote:
> > 
> > > My friend, there is a wide deep secret world for hackers. We have
> > > no any idea about that world. Look, there is nothing called a 100%
> > > fact in our world. Believe me, what we see in software is just
> > > what "THEY" want us to see.
> > 
> > I think you have no idea how some processes work.
> > 
> > We have cryptographic digest methods to verify source code and final
> > builds. In theory, someone could inject bad code if nobody would
> > review it properly of course. But especially for compilers such code
> > would be detected soon and no insane person in such projects would
> > just merge code without reviewing it.
> > 
> > That applies for open source - not if you just download a compiled
> > binary from a ftp server in the open web of course :D
> 
> Aha! "In theory, someone could inject bad code", you admit my theory.

In theory, Ken Thompson's compromised compiler hack could be at work[1].

In practice, though, especially for open-source projects where you can
take the code and compile it with any of number of 3rd party compilers
(at least one of which would be unlikely to have been compiled by a
compromised compiler, so would be "clean"), or, for that matter, you can
freely *modify* the code to replace arbitrary parts of it with
semantically-equivalent code that no longer matches the hack-triggering
pattern, it would take an unreal amount of influence over the entire
world to be able to pull off such a hack.

If somebody actually wielded that much influence over your software, you
already have far bigger problems to worry about; whether or not your
software is being compiled with hidden backdoors is already a moot
question. :-D  (And your efforts to write only "purely" your own code
would also be futile anyway, esp. in a Thompson's-hack scenario.)


[1] 
https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_ReflectionsonTrustingTrust.pdf


T

-- 
The early bird gets the worm. Moral: ewww...


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 16:37:35 UTC, frame wrote:

On Thursday, 28 July 2022 at 16:17:16 UTC, pascal111 wrote:

My friend, there is a wide deep secret world for hackers. We 
have no any idea about that world. Look, there is nothing 
called a 100% fact in our world. Believe me, what we see in 
software is just what "THEY" want us to see.


I think you have no idea how some processes work.

We have cryptographic digest methods to verify source code and 
final builds. In theory, someone could inject bad code if 
nobody would review it properly of course. But especially for 
compilers such code would be detected soon and no insane person 
in such projects would just merge code without reviewing it.


That applies for open source - not if you just download a 
compiled binary from a ftp server in the open web of course :D


Aha! "In theory, someone could inject bad code", you admit my 
theory.


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread frame via Digitalmars-d-learn

On Thursday, 28 July 2022 at 16:17:16 UTC, pascal111 wrote:

My friend, there is a wide deep secret world for hackers. We 
have no any idea about that world. Look, there is nothing 
called a 100% fact in our world. Believe me, what we see in 
software is just what "THEY" want us to see.


I think you have no idea how some processes work.

We have cryptographic digest methods to verify source code and 
final builds. In theory, someone could inject bad code if nobody 
would review it properly of course. But especially for compilers 
such code would be detected soon and no insane person in such 
projects would just merge code without reviewing it.


That applies for open source - not if you just download a 
compiled binary from a ftp server in the open web of course :D


Re: BASIC "sgn" function equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 15:38:18 UTC, H. S. Teoh wrote:
On Thu, Jul 28, 2022 at 03:10:19PM +, pascal111 via 
Digitalmars-d-learn wrote:

> [...]

[...]

[...]


AFAIK, all D compilers ship with full Phobos source code. On my 
installation, it's in 
/usr/lib/gcc/x86_64-linux-gnu/11/include/d/*. You can probably 
find yours in a similar (or the same) location. Under that 
directory, just look into std/math/*.d for the std.math 
functions. For example, .sgn is in std/math/traits.d.


In general, all 3 D compilers ship with the same Phobos 
sources, except perhaps in a few places where some 
compiler-specific fixes were needed. Generally, though, I think 
the idea is to merge all such changes upstream under version() 
blocks so that we can use the same Phobos sources for all 
compilers.



T


I checked this path 
"/usr/lib/gcc/x86_64-linux-gnu/11/include/d/*" yesterday in my 
Ubuntu. I think you are right. Thanks!


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 16:13:17 UTC, frame wrote:

On Thursday, 28 July 2022 at 14:57:36 UTC, pascal111 wrote:

well between US and some other countries like "Russia", and 
they are using US products like C compilers, so with some way 
we have a doubt that US developed compilers with a way to 
accept kind of messages or something like that, so my comment 
has no meaning to the compiler except if I knew the secret 
patterns or I do it accidentally.


Wait. You mean asterisks in comments may trigger some secret 
backdoor function in C-compilers? Come on :D


My friend, there is a wide deep secret world for hackers. We have 
no any idea about that world. Look, there is nothing called a 
100% fact in our world. Believe me, what we see in software is 
just what "THEY" want us to see.


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread frame via Digitalmars-d-learn

On Thursday, 28 July 2022 at 14:57:36 UTC, pascal111 wrote:

well between US and some other countries like "Russia", and 
they are using US products like C compilers, so with some way 
we have a doubt that US developed compilers with a way to 
accept kind of messages or something like that, so my comment 
has no meaning to the compiler except if I knew the secret 
patterns or I do it accidentally.


Wait. You mean asterisks in comments may trigger some secret 
backdoor function in C-compilers? Come on :D


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 15:55:04 UTC, kdevel wrote:

On Thursday, 28 July 2022 at 14:57:36 UTC, pascal111 wrote:

[...]
Sure. What effect do YOU hope to causes or prevent by writing

```
/**/
```

between all of your functions?


I'm normal programmer, by mean that I'm not so expert in C 
matters to know really if there are particular patterns that 
have specific meanings for the compiler or not.


I was asking why /you/ put



I'm trying to answer you; remember that your question isn't 
simple as it seemed, so it needs rich explaining.



```
/**/
```

between function definitions. You cannot or do not want to 
answer that question. I think that this pattern or habit is not 
your invention. You borrowed that style from someone else and 
did not ask him or her for its purpose. Right?


Really I want to answer you, but yes, maybe you are right that I 
saw this pattern before, but I don't remember where? really I 
don't remember where I saw it. I thought it's useless pattern.


Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 15:25:00 UTC, Alexander Zhirov wrote:
[...]

Everything falls on the same error.

```sh
checking for suffix of object files... configure: error: in 
`/home/thinstation/source/gcc/12.1.0/build/i586-pc-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: 
cannot compile

See `config.log' for more details


Have you looked into config.log? The errors are frequently 
located in the second half of the output.


In general, nothing happened. I've already tried everything. 
Here is the result, posted 
[here](https://pastebin.com/76gnneKZ).


In such cases I usually take the error message, here

``
configure: error: cannot compute suffix of object files:
``

and search with google for it. Google points me to stackoverflow:



```
This issue is caused by dyanmic link library path issue when the 
test programs try to link against libmpc/libmpfr/libgmp.


Append below environment variable to allow ld link against the 
correct so file:


export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/mpc/lib/

Then try build gcc again.
```

Does this help?


Re: Build for i586

2022-07-28 Thread Alexander Zhirov via Digitalmars-d-learn

On Thursday, 28 July 2022 at 16:02:11 UTC, kdevel wrote:
On Thursday, 28 July 2022 at 15:25:00 UTC, Alexander Zhirov 
wrote:

On Thursday, 28 July 2022 at 13:16:26 UTC, kdevel wrote:
On Thursday, 28 July 2022 at 12:45:51 UTC, Alexander Zhirov 
wrote:

[...]
I have already downloaded the latest GCC sources, nothing 
compiles anyway.


How did you manage to get hold of this compiler?

```
/root/usr/program/gcc/9.5.0/install/bin/cc
```


Where does this compiler come from?


This is an unpacked archive from an official source from the GNU 
website


https://ftp.mpi-inf.mpg.de/mirrors/gnu/mirror/gcc.gnu.org/pub/gcc/releases/gcc-9.5.0/


Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 15:25:00 UTC, Alexander Zhirov wrote:

On Thursday, 28 July 2022 at 13:16:26 UTC, kdevel wrote:
On Thursday, 28 July 2022 at 12:45:51 UTC, Alexander Zhirov 
wrote:

[...]
I have already downloaded the latest GCC sources, nothing 
compiles anyway.


How did you manage to get hold of this compiler?

```
/root/usr/program/gcc/9.5.0/install/bin/cc
```


Where does this compiler come from?


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 14:57:36 UTC, pascal111 wrote:

[...]
Sure. What effect do YOU hope to causes or prevent by writing

```
/**/
```

between all of your functions?


I'm normal programmer, by mean that I'm not so expert in C 
matters to know really if there are particular patterns that 
have specific meanings for the compiler or not.


I was asking why /you/ put

```
/**/
```

between function definitions. You cannot or do not want to answer 
that question. I think that this pattern or habit is not your 
invention. You borrowed that style from someone else and did not 
ask him or her for its purpose. Right?





Re: BASIC "sgn" function equivalent

2022-07-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 28, 2022 at 03:10:19PM +, pascal111 via Digitalmars-d-learn 
wrote:
> On Thursday, 28 July 2022 at 15:03:34 UTC, H. S. Teoh wrote:
> > On Thu, Jul 28, 2022 at 02:30:38PM +, pascal111 via
> > Digitalmars-d-learn wrote: [...]
> > > Of-course D has a built in "sgn" function, but I like to do it
> > > with my hands to be sure of code, I'm some doubtful and don't
> > > trust alien works.
> > 
> > Just use the source, Luke!  Phobos is open source for a reason.
> > 
> > 
> > https://github.com/dlang/phobos/blob/8280b1e7de6cca4dc9a593431591054a5b3aa288/std/math/traits.d#L694
[...]
> I think Phobos is the big library of D, is it the same one with gdc
> compiler too? I'm using gdc compiler.

AFAIK, all D compilers ship with full Phobos source code. On my
installation, it's in /usr/lib/gcc/x86_64-linux-gnu/11/include/d/*. You
can probably find yours in a similar (or the same) location. Under that
directory, just look into std/math/*.d for the std.math functions. For
example, .sgn is in std/math/traits.d.

In general, all 3 D compilers ship with the same Phobos sources, except
perhaps in a few places where some compiler-specific fixes were needed.
Generally, though, I think the idea is to merge all such changes
upstream under version() blocks so that we can use the same Phobos
sources for all compilers.


T

-- 
What's the difference between a 4D tube and an overweight Dutchman?  One is a 
hollow spherinder, and the other is a spherical Hollander.


Re: BASIC "sgn" function equivalent

2022-07-28 Thread Antonio via Digitalmars-d-learn

On Thursday, 28 July 2022 at 15:03:34 UTC, H. S. Teoh wrote:

Just use the source, Luke!  Phobos is open source for a reason.


https://github.com/dlang/phobos/blob/8280b1e7de6cca4dc9a593431591054a5b3aa288/std/math/traits.d#L694


T


:-)

```d
// @@@TODO@@@: make this faster
```



Re: Build for i586

2022-07-28 Thread Alexander Zhirov via Digitalmars-d-learn

On Thursday, 28 July 2022 at 13:16:26 UTC, kdevel wrote:
On Thursday, 28 July 2022 at 12:45:51 UTC, Alexander Zhirov 
wrote:

[...]
I have already downloaded the latest GCC sources, nothing 
compiles anyway.


How did you manage to get hold of this compiler?

```
/root/usr/program/gcc/9.5.0/install/bin/cc
```


Everything falls on the same error.

```sh
checking for suffix of object files... configure: error: in 
`/home/thinstation/source/gcc/12.1.0/build/i586-pc-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: 
cannot compile

See `config.log' for more details


Have you looked into config.log? The errors are frequently 
located in the second half of the output.


In general, nothing happened. I've already tried everything. Here 
is the result, posted [here](https://pastebin.com/76gnneKZ).


Re: BASIC "sgn" function equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 15:03:34 UTC, H. S. Teoh wrote:
On Thu, Jul 28, 2022 at 02:30:38PM +, pascal111 via 
Digitalmars-d-learn wrote: [...]
Of-course D has a built in "sgn" function, but I like to do it 
with my hands to be sure of code, I'm some doubtful and don't 
trust alien works.


Just use the source, Luke!  Phobos is open source for a reason.


https://github.com/dlang/phobos/blob/8280b1e7de6cca4dc9a593431591054a5b3aa288/std/math/traits.d#L694


T


I think Phobos is the big library of D, is it the same one with 
gdc compiler too? I'm using gdc compiler.


Re: BASIC "sgn" function equivalent

2022-07-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 28, 2022 at 02:30:38PM +, pascal111 via Digitalmars-d-learn 
wrote:
[...]
> Of-course D has a built in "sgn" function, but I like to do it with my
> hands to be sure of code, I'm some doubtful and don't trust alien
> works.

Just use the source, Luke!  Phobos is open source for a reason.


https://github.com/dlang/phobos/blob/8280b1e7de6cca4dc9a593431591054a5b3aa288/std/math/traits.d#L694


T

-- 
Sometimes the best solution to morale problems is just to fire all of the 
unhappy people. -- despair.com


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 14:44:53 UTC, kdevel wrote:

On Thursday, 28 July 2022 at 13:58:24 UTC, pascal111 wrote:
[...]
Precisely in what way? I am not kidding. I am seriously 
asking the question: In what way may a C or C++ compiler 
benefit from lines between functions which contain only 
comments consisting of nothing else than asterisks?


Seriously and accurately, if you meant that, we don't know how 
developers of C compilers programmed their compilers, for 
example, maybe there's a secret way the developers programmed 
their compiler so that a special pattern of comments can have 
a particular meaning to the compilers. We don't know! maybe 
it's true.


Sure. What effect do YOU hope to causes or prevent by writing

```
/**/
```

between all of your functions?


I'm normal programmer, by mean that I'm not so expert in C 
matters to know really if there are particular patterns that have 
specific meanings for the compiler or not. I know this forum is 
not for political topics, but by the way I would like to mention 
something: everyone knows that the affairs are not well between 
US and some other countries like "Russia", and they are using US 
products like C compilers, so with some way we have a doubt that 
US developed compilers with a way to accept kind of messages or 
something like that, so my comment has no meaning to the compiler 
except if I knew the secret patterns or I do it accidentally.


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 13:58:24 UTC, pascal111 wrote:
[...]
Precisely in what way? I am not kidding. I am seriously asking 
the question: In what way may a C or C++ compiler benefit from 
lines between functions which contain only comments consisting 
of nothing else than asterisks?


Seriously and accurately, if you meant that, we don't know how 
developers of C compilers programmed their compilers, for 
example, maybe there's a secret way the developers programmed 
their compiler so that a special pattern of comments can have a 
particular meaning to the compilers. We don't know! maybe it's 
true.


Sure. What effect do YOU hope to causes or prevent by writing

```
/**/
```

between all of your functions?



Re: BASIC "sgn" function equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 12:13:31 UTC, Antonio wrote:

On Thursday, 28 July 2022 at 12:02:54 UTC, pascal111 wrote:
I'm making an equivalent of "sgn" function of BASIC language, 
and I used "(T)" in its definition, but the function can 
receive wrong data by passing string data to it, how we can 
solve it?



Use isFloating!T and isIntegral!T traits.

The standard library **sng** function is a good example:

https://dlang.org/library/std/math/traits/sgn.html


Of-course D has a built in "sgn" function, but I like to do it 
with my hands to be sure of code, I'm some doubtful and don't 
trust alien works.


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 13:29:01 UTC, kdevel wrote:

On Thursday, 28 July 2022 at 12:44:19 UTC, pascal111 wrote:

[...]
Do you think it helps the compiler if you put these

`/**/`

between your functions? Or is there anybody else who benefits 
from it?


"Do you think it helps the compiler if you put these"
Are you serious? maybe it's useful for compilers with some way.


Precisely in what way? I am not kidding. I am seriously asking 
the question: In what way may a C or C++ compiler benefit from 
lines between functions which contain only comments consisting 
of nothing else than asterisks?


Seriously and accurately, if you meant that, we don't know how 
developers of C compilers programmed their compilers, for 
example, maybe there's a secret way the developers programmed 
their compiler so that a special pattern of comments can have a 
particular meaning to the compilers. We don't know! maybe it's 
true.


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 13:06:03 UTC, kdevel wrote:

On Thursday, 28 July 2022 at 12:25:05 UTC, pascal111 wrote:

[...]

ofix.c: In function 'fix':
ofix.c:7:3: warning: 'z' is used uninitialized 
[-Wuninitialized]

7 | y=modf(x,z);
  |   ^
ofix.c:5:12: note: 'z' was declared here
5 | double y,* z;
  |^
```

I would also like to complain about the double assignment to 
`y`.


"fix" function is the C version of BASIC standard one I made, 
it's the equivalent of "trunc" in D, but the code I programmed 
for "fix" was with TC++ , and it worked in DOS emulators with 
no problem,


"Code works" and "Code is correct" are two distinct categories. 
The compiler's warnings show that your code is not correct and 
not that it will necessarily not work. Incorrect code may work 
accidentally.




for that we are - guys of C - prefer C of other languages like 
Pascal, because C allow us to have working programs although they 
are not 100% correct, but something like Pascal is so hard and 
difficult in its compiling, it'll give us an error for even a so 
small expression, so we don't like the much complaints of 
compilers, and C is so forgiving language.


As a (future) software developer you are required to not just 
produce code that "works" "with no problem" but also code that 
is correct. "Correct" here means that the code adheres to the 
specifications of the language.


Writing incorrect code is like "fixing" a "broken" fuse with 
tin foil.


I have no idea how gcc will treat my code, but I think you are 
right that some other compilers will refuse such code, because 
VC++ 6 refused many of these functions codes I programmed with 
TC++ compiler.


The incorrectness of your C code does not depend on the 
compiler brand.


I have to change the compiler, not the code!



Re: does the format of coverage files have a name?

2022-07-28 Thread Paul Backus via Digitalmars-d-learn

On Monday, 25 July 2022 at 13:17:41 UTC, Moth wrote:

or was the .lst extension chosen arbitrarily?

my text editor [notepad++] thinks it's COBOL for some reason 
but that's obviously not correct, so i'm wondering if it has an 
official spec or anything. knowing the name of it would help - 
maybe my editor already has syntax highlighting for it.


I think it's a bespoke format with no official name. The closest 
thing to a spec is this page:


https://dlang.org/articles/code_coverage.html


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 12:44:19 UTC, pascal111 wrote:

[...]
Do you think it helps the compiler if you put these

`/**/`

between your functions? Or is there anybody else who benefits 
from it?


"Do you think it helps the compiler if you put these"
Are you serious? maybe it's useful for compilers with some way.


Precisely in what way? I am not kidding. I am seriously asking 
the question: In what way may a C or C++ compiler benefit from 
lines between functions which contain only comments consisting of 
nothing else than asterisks?




Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 12:45:51 UTC, Alexander Zhirov wrote:
[...]
I have already downloaded the latest GCC sources, nothing 
compiles anyway.


How did you manage to get hold of this compiler?

```
/root/usr/program/gcc/9.5.0/install/bin/cc
```


Everything falls on the same error.

```sh
checking for suffix of object files... configure: error: in 
`/home/thinstation/source/gcc/12.1.0/build/i586-pc-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot 
compile

See `config.log' for more details


Have you looked into config.log? The errors are frequently 
located in the second half of the output.




Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 12:25:05 UTC, pascal111 wrote:

[...]

ofix.c: In function 'fix':
ofix.c:7:3: warning: 'z' is used uninitialized 
[-Wuninitialized]

7 | y=modf(x,z);
  |   ^
ofix.c:5:12: note: 'z' was declared here
5 | double y,* z;
  |^
```

I would also like to complain about the double assignment to 
`y`.


"fix" function is the C version of BASIC standard one I made, 
it's the equivalent of "trunc" in D, but the code I programmed 
for "fix" was with TC++ , and it worked in DOS emulators with 
no problem,


"Code works" and "Code is correct" are two distinct categories. 
The compiler's warnings show that your code is not correct and 
not that it will necessarily not work. Incorrect code may work 
accidentally.


As a (future) software developer you are required to not just 
produce code that "works" "with no problem" but also code that is 
correct. "Correct" here means that the code adheres to the 
specifications of the language.


Writing incorrect code is like "fixing" a "broken" fuse with tin 
foil.


I have no idea how gcc will treat my code, but I think you are 
right that some other compilers will refuse such code, because 
VC++ 6 refused many of these functions codes I programmed with 
TC++ compiler.


The incorrectness of your C code does not depend on the compiler 
brand.


Re: BASIC "sgn" function equivalent

2022-07-28 Thread Adam D Ruppe via Digitalmars-d-learn

On Thursday, 28 July 2022 at 12:02:54 UTC, pascal111 wrote:
I'm making an equivalent of "sgn" function of BASIC language, 
and I used "(T)" in its definition, but the function can 
receive wrong data by passing string data to it, how we can 
solve it?


There's no need to do the complication of a template, just do a 
normal function taking a `double`. You can add overloads if you 
want like one taking a `long` and/or `int` but those would cover 
all types that have signs.


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 12:36:59 UTC, kdevel wrote:

On Thursday, 28 July 2022 at 12:26:50 UTC, pascal111 wrote:

[...]
Aha! you mean "/**/", 
it has no job, just to separate between functions codes.


Do you think it helps the compiler if you put these

`/**/`

between your functions? Or is there anybody else who benefits 
from it?


"Do you think it helps the compiler if you put these"
Are you serious? maybe it's useful for compilers with some way.

"between your functions? Or is there anybody else who benefits
 from it?"

Your question isn't clear, but the code is free for learning 
purposes. I shared it in public for everyone thinks it useful to 
him.


Re: Build for i586

2022-07-28 Thread Alexander Zhirov via Digitalmars-d-learn

On Thursday, 28 July 2022 at 11:40:09 UTC, kdevel wrote:
On Thursday, 28 July 2022 at 10:39:06 UTC, Alexander Zhirov 
wrote:

[...]

I don't understand what I need to do.


You wrote

At first I thought that I needed to rebuild the GCC 
compiler for the i586
architecture. I downloaded GCC 9.5.0 and started the 
installation:


Then you wrote that this process failed. In your next post you 
quoted some code from the shell:


```
# /root/usr/program/gcc/9.5.0/install/bin/cc app.o -o app 
-L/root/usr/program/ldc/1.30/install/lib -lphobos2-ldc -ldrun
time-ldc -Wl,--gc-sections -lrt -ldl -lpthread -lm -m32 
-march=geode

# ./app
Illegal instruction
```

I read this as if you eventually succeeded in compiling your 
GCC 9.5.0. If you repeat that build but use the switch


```
--with-arch-32=pentium3
```

in the configure command your generated GCC 9.5.0 will compile 
32-Bit code for the pentium3. I mean instead of


```
# ../source/configure --prefix=$PWD/../install_i586 
--enable-shared --enable-threads=posix --enable-__cxa_atexit 
--enable-clocale=gnu --enable-languages=c,c++,d 
--target=i586-pc-linux-gnu --disable-multilib 
--with-multilib-list=m32

```

type

```
# ../source/configure --prefix=$PWD/../install_i586 
--enable-shared --enable-threads=posix --enable-__cxa_atexit 
--enable-clocale=gnu --enable-languages=c,c++,d 
--target=i586-pc-linux-gnu --disable-multilib 
--with-multilib-list=m32 --with-arch-32=pentium3

```


I have already downloaded the latest GCC sources, nothing 
compiles anyway. Everything falls on the same error.


```sh
checking for suffix of object files... configure: error: in 
`/home/thinstation/source/gcc/12.1.0/build/i586-pc-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot 
compile

See `config.log' for more details
make[1]: *** [Makefile:16026: configure-target-libgcc] Error 1
make[1]: *** Waiting for unfinished jobs
```


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 12:26:50 UTC, pascal111 wrote:

[...]
Aha! you mean "/**/", 
it has no job, just to separate between functions codes.


Do you think it helps the compiler if you put these

`/**/`

between your functions? Or is there anybody else who benefits 
from it?


Re: BASIC "sgn" function equivalent

2022-07-28 Thread Antonio via Digitalmars-d-learn

On Thursday, 28 July 2022 at 12:13:31 UTC, Antonio wrote:




Use isFloating!T and isIntegral!T traits.

The standard library **sng** function is a good example:

https://dlang.org/library/std/math/traits/sgn.html


```d
import std.traits : isFloatingPoint, isIntegral;

int sgn(T)(T x) if (isFloatingPoint!T || isIntegral!T)
{
  if(x<0)
return -1;
  else if(x>0)
return 1;
  else
return 0;
}

void main()
{
   import std.stdio;

   writeln(sgn(-1234));
   sgn(-1213.32).writeln;
   1234.sgn.writeln;
}
```


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 12:15:19 UTC, kdevel wrote:

On Wednesday, 27 July 2022 at 18:19:34 UTC, pascal111 wrote:

[...]


1. What exact purpose do these

```
/**/
```

[...]


Aha! you mean "/**/", it 
has no job, just to separate between functions codes.


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 12:15:19 UTC, kdevel wrote:

On Wednesday, 27 July 2022 at 18:19:34 UTC, pascal111 wrote:
I made a library of some useful functions while I was studying 
C, and I'm curious to know if D has equivalents or some ones 
for some of my functions, or I have to retype 'em again in D.


The library link:
https://github.com/pascal111-fra/turbo-c-programs/blob/main/COLLECT2.H


1. What exact purpose do these

```
/**/
```

have?

2.
```
double fix(double x)
{

double y,* z;

y=modf(x,z);
y=*z;

return y;

}
```
Besides the remarkable formatting there is an issue with the 
code. According to the manual the modf function


```
double modf(double x, double *iptr);
```

stores "The integral part [of x] [...] in the location pointed 
to by iptr." If you ask the compiler for help (e.g. `gcc -Wall 
-pedantic`) it will tell you what's wrong:


```
ofix.c: In function 'fix':
ofix.c:7:3: warning: 'z' is used uninitialized [-Wuninitialized]
7 | y=modf(x,z);
  |   ^
ofix.c:5:12: note: 'z' was declared here
5 | double y,* z;
  |^
```

I would also like to complain about the double assignment to 
`y`.


"fix" function is the C version of BASIC standard one I made, 
it's the equivalent of "trunc" in D, but the code I programmed 
for "fix" was with TC++ , and it worked in DOS emulators with no 
problem, I have no idea how gcc will treat my code, but I think 
you are right that some other compilers will refuse such code, 
because VC++ 6 refused many of these functions codes I programmed 
with TC++ compiler.


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Wednesday, 27 July 2022 at 18:19:34 UTC, pascal111 wrote:
I made a library of some useful functions while I was studying 
C, and I'm curious to know if D has equivalents or some ones 
for some of my functions, or I have to retype 'em again in D.


The library link:
https://github.com/pascal111-fra/turbo-c-programs/blob/main/COLLECT2.H


1. What exact purpose do these

```
/**/
```

have?

2.
```
double fix(double x)
{

double y,* z;

y=modf(x,z);
y=*z;

return y;

}
```
Besides the remarkable formatting there is an issue with the 
code. According to the manual the modf function


```
double modf(double x, double *iptr);
```

stores "The integral part [of x] [...] in the location pointed to 
by iptr." If you ask the compiler for help (e.g. `gcc -Wall 
-pedantic`) it will tell you what's wrong:


```
ofix.c: In function 'fix':
ofix.c:7:3: warning: 'z' is used uninitialized [-Wuninitialized]
7 | y=modf(x,z);
  |   ^
ofix.c:5:12: note: 'z' was declared here
5 | double y,* z;
  |^
```

I would also like to complain about the double assignment to `y`.


Re: BASIC "sgn" function equivalent

2022-07-28 Thread Antonio via Digitalmars-d-learn

On Thursday, 28 July 2022 at 12:02:54 UTC, pascal111 wrote:
I'm making an equivalent of "sgn" function of BASIC language, 
and I used "(T)" in its definition, but the function can 
receive wrong data by passing string data to it, how we can 
solve it?



Use isFloating!T and isIntegral!T traits.

The standard library **sng** function is a good example:

https://dlang.org/library/std/math/traits/sgn.html


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread pascal111 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 11:13:19 UTC, Dennis wrote:

On Wednesday, 27 July 2022 at 18:19:34 UTC, pascal111 wrote:

The library link:
https://github.com/pascal111-fra/turbo-c-programs/blob/main/COLLECT2.H


It would help if the functions had a comment explaining what 
they're supposed to do, but it looks like most of them are 
string functions. In D, you can concatenate strings with the 
`~` operator, and utility functions like `strip` and `replace` 
are in the `std.string` module:


https://dlang.org/phobos/std_string.html

I also think you defined the equivalent of these functions:
```D
import std.algorithm: swap;
import std.math: sgn, trunc;
```


As you mentioned, I retyped some of 'em:

module dcollect;

import std.stdio;
import std.conv;

//

string strleft(const string ch, int n)
{

string ch_sub;

for(int i=0; i=0; i--)
ch_rev~=ch[i];


return ch_rev;


}

/*/

string strright(const string ch, int n)
{

string ch_sub1,
ch_sub2;

ch_sub1=strreverse(ch);

ch_sub2=strleft(ch_sub1, n);

ch_sub1=strreverse(ch_sub2);

return ch_sub1;

}

/*/

void swap(T)(ref T x,ref T y)
{

T z;

z=x;
x=y;
y=z;

}

/*/

int sgn(T)(T x)
{

if(x<0)
return -1;
else if(x>0)
return 1;
else
return 0;

}



BASIC "sgn" function equivalent

2022-07-28 Thread pascal111 via Digitalmars-d-learn
I'm making an equivalent of "sgn" function of BASIC language, and 
I used "(T)" in its definition, but the function can receive 
wrong data by passing string data to it, how we can solve it?


int sgn(T)(T x)
{

if(x<0)
return -1;
else if(x>0)
return 1;
else
return 0;

}


Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 10:39:06 UTC, Alexander Zhirov wrote:
[...]

I don't understand what I need to do.


You wrote

At first I thought that I needed to rebuild the GCC compiler 
for the i586
architecture. I downloaded GCC 9.5.0 and started the 
installation:


Then you wrote that this process failed. In your next post you 
quoted some code from the shell:


```
# /root/usr/program/gcc/9.5.0/install/bin/cc app.o -o app 
-L/root/usr/program/ldc/1.30/install/lib -lphobos2-ldc -ldrun
time-ldc -Wl,--gc-sections -lrt -ldl -lpthread -lm -m32 
-march=geode

# ./app
Illegal instruction
```

I read this as if you eventually succeeded in compiling your GCC 
9.5.0. If you repeat that build but use the switch


```
--with-arch-32=pentium3
```

in the configure command your generated GCC 9.5.0 will compile 
32-Bit code for the pentium3. I mean instead of


```
# ../source/configure --prefix=$PWD/../install_i586 
--enable-shared --enable-threads=posix --enable-__cxa_atexit 
--enable-clocale=gnu --enable-languages=c,c++,d 
--target=i586-pc-linux-gnu --disable-multilib 
--with-multilib-list=m32

```

type

```
# ../source/configure --prefix=$PWD/../install_i586 
--enable-shared --enable-threads=posix --enable-__cxa_atexit 
--enable-clocale=gnu --enable-languages=c,c++,d 
--target=i586-pc-linux-gnu --disable-multilib 
--with-multilib-list=m32 --with-arch-32=pentium3

```


Iterating over mixin template members

2022-07-28 Thread Hipreme via Digitalmars-d-learn
So, I've came to a situation where I must use mixin template for 
defining members overloads, like:

```d
mixin template OverloadGen()
{
static if(hasMethod!(typeof(this), "add", int, int))
{
float add(float x, float y){return x+y;}
}
static if(hasMethod!(typeof(this), "mul", int, int))
{
float mul(float x, float y){return x*y;}
}
}

```


I know this example is obvious, but I'm using this for a far more 
complex, so I need that to work.


The current way I tried to solve that was using string mixins 
such as:


```d
enum mixOverloadGen()
{
return q{
mixin OverloadGen __ogen__;
static foreach(mem; __traits(allMembers, __ogen__))
{
mixin("alias ",mem," = __ogen__.",mem,";");
}
};
}

class Tester
{
int add(int, int){return 0;}
mixin(mixOverloadGen);
}
```

The problem doing that is that I can have access to `__ogen__`, 
which makes code like that valid: `tester.__ogen__.add`. I can't 
make `private mixin OverloadGen __ogen__`, because I won't be 
able to publicly access my overloads.



And doing `static foreach(mem; mixin OverloadGen)` is also 
invalid, tried with allMembers, so, this is my current solution, 
the other thing I could do is instead of aliasing to the mixin 
members, I could make them private and declare a public function 
inside my string mixin which calls those, which is just wasteful: 
increase compile time, runtime usage and code complexity.


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread Dennis via Digitalmars-d-learn

On Wednesday, 27 July 2022 at 18:19:34 UTC, pascal111 wrote:

The library link:
https://github.com/pascal111-fra/turbo-c-programs/blob/main/COLLECT2.H


It would help if the functions had a comment explaining what 
they're supposed to do, but it looks like most of them are string 
functions. In D, you can concatenate strings with the `~` 
operator, and utility functions like `strip` and `replace` are in 
the `std.string` module:


https://dlang.org/phobos/std_string.html

I also think you defined the equivalent of these functions:
```D
import std.algorithm: swap;
import std.math: sgn, trunc;
```


Re: Build for i586

2022-07-28 Thread Alexander Zhirov via Digitalmars-d-learn

On Thursday, 28 July 2022 at 10:26:36 UTC, kdevel wrote:
On Thursday, 28 July 2022 at 06:12:49 UTC, Alexander Zhirov 
wrote:
On Thursday, 28 July 2022 at 06:01:17 UTC, Alexander Zhirov 
wrote:

```sh
/root/usr/program/gcc/9.5.0/install/bin/cc app.o -o app 
-L/root/usr/program/ldc/1.30/install/lib -lphobos2-ldc 
-ldruntime-ldc -Wl,--gc-sections -lrt -ldl -lpthread -lm -m32

```


So you eventually built GCC 9.5.0? I have used the

```
   --with-arch-32=pentium3
```

option in the configure step for compiling GCC 12.1.0. The 
build gdc

generates codes which successfully runs on my Pentium III.


The only thing I did (but it still didn't work) was I 
[built](https://wiki.dlang.org/Building_under_Posix#Building_DMD) 
a `dmd` compiler:


```sh
root@host ~/program # dmd --version
DMD32 D Compiler v2.100.1-3-g76e3b4137
Copyright (C) 1999-2022 by The D Language Foundation, All Rights 
Reserved written by Walter Bright


root@host ~/program # dmd -mcpu=native app.d -v
predefs   DigitalMars LittleEndian D_Version2 all Posix ELFv1 
linux CRuntime_Glibc CppRuntime_Gcc D_InlineAsm D_InlineAsm_X86 
X86 D_PIC assert D_PreConditions D_PostConditions D_Invariants 
D_ModuleInfo D_Exceptions D_TypeInfo D_HardFloat

binarydmd
version   v2.100.1-3-g76e3b4137
config/root/usr/program/dmd/2.100.1/usr/bin/dmd.conf
DFLAGS
-I/root/usr/program/dmd/2.100.1/usr/bin/../include/dmd/druntime/import -I/root/usr/program/dmd/2.100.1/usr/bin/../include/dmd/phobos -L-L/root/usr/program/dmd/2.100.1/usr/bin/../lib -L--export-dynamic -fPIC

parse app
importall app
importobject
(/root/usr/program/dmd/2.100.1/usr/bin/../include/dmd/druntime/import/object.d)

...
function  std.typecons.Tuple!(uint, "data", uint, 
"count").Tuple.opCmp!(const(Tuple!(uint, "data", uint, 
"count"))).opCmp
cc app.o -o app -m32 -Xlinker --export-dynamic 
-L/root/usr/program/dmd/2.100.1/usr/bin/../lib -Xlinker -Bstatic 
-lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl


root@host ~/program # ./app
Illegal instruction
```


Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 00:46:19 UTC, pascal111 wrote:

On Thursday, 28 July 2022 at 00:36:54 UTC, ryuukk_ wrote:
I don't remember the exact syntax for GDC, but it should be 
pretty similar to DMD


You need to pass the module to the compiler

gdc main.d dcollect.d


I'm using CODE::BLOCKS IDE. How can I do it through it?


You should probably ask this question in a CODE::BLOCKS forum.

Further reading:

- Benefits of Not Using an IDE
  

- Why You Shouldn’t Always Use an IDE
  



Re: Build for i586

2022-07-28 Thread Alexander Zhirov via Digitalmars-d-learn

On Thursday, 28 July 2022 at 10:26:36 UTC, kdevel wrote:
On Thursday, 28 July 2022 at 06:12:49 UTC, Alexander Zhirov 
wrote:
On Thursday, 28 July 2022 at 06:01:17 UTC, Alexander Zhirov 
wrote:

```sh
/root/usr/program/gcc/9.5.0/install/bin/cc app.o -o app 
-L/root/usr/program/ldc/1.30/install/lib -lphobos2-ldc 
-ldruntime-ldc -Wl,--gc-sections -lrt -ldl -lpthread -lm -m32

```


So you eventually built GCC 9.5.0? I have used the

```
   --with-arch-32=pentium3
```

option in the configure step for compiling GCC 12.1.0. The 
build gdc

generates codes which successfully runs on my Pentium III.


I don't understand what I need to do.


Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn

On Thursday, 28 July 2022 at 06:12:49 UTC, Alexander Zhirov wrote:
On Thursday, 28 July 2022 at 06:01:17 UTC, Alexander Zhirov 
wrote:

```sh
/root/usr/program/gcc/9.5.0/install/bin/cc app.o -o app 
-L/root/usr/program/ldc/1.30/install/lib -lphobos2-ldc 
-ldruntime-ldc -Wl,--gc-sections -lrt -ldl -lpthread -lm -m32

```


So you eventually built GCC 9.5.0? I have used the

```
   --with-arch-32=pentium3
```

option in the configure step for compiling GCC 12.1.0. The build 
gdc

generates codes which successfully runs on my Pentium III.



Re: Build for i586

2022-07-28 Thread Alexander Zhirov via Digitalmars-d-learn

On Thursday, 28 July 2022 at 07:16:13 UTC, user1234 wrote:
that would be something like `--mcpu=i686 --mattrs=-mmx,-sse` 
and maybe more to be sure.


Fails...

```sh
# ldc2 --mcpu=i686 --mattr=-mmx,-sse app.d
# ./app
Illegal instruction
```


Re: Build for i586

2022-07-28 Thread user1234 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 06:12:49 UTC, Alexander Zhirov wrote:

On Thursday, 28 July 2022 at 06:01:17 UTC, Alexander Zhirov
> x86- 32-bit X86: Pentium-Pro and above
I also tried with `i586` and `pentium` - the result is the same.


Pentium Pro and above means at least i686. i586 is Pentium1 which 
is less featured.
That means that you cant do much, however you can try to tune the 
i686 target and disable emiting of the instructions that were 
added from the Pentium Pro. Maybe that the produced instruction 
will then be compatible.


that would be something like `--mcpu=i686 --mattrs=-mmx,-sse` and 
maybe more to be sure.



Other things: "Registered Targets: ... " means that maybe the LDC 
developers could add the i586 target but did not consider useful 
to add this is old processor (e.g Pentium1). For that you should 
ask them if you can and how activate the target when you build 
ldc2 on your old Geode.






Re: Build for i586

2022-07-28 Thread user1234 via Digitalmars-d-learn

On Thursday, 28 July 2022 at 07:16:13 UTC, user1234 wrote:
On Thursday, 28 July 2022 at 06:12:49 UTC, Alexander Zhirov 
wrote:

[...]


Pentium Pro and above means at least i686. i586 is Pentium1 
which is less featured.
That means that you cant do much, however you can try to tune 
the i686 target and disable emiting of the instructions that 
were added from the Pentium Pro. Maybe that the produced 
instruction will then be compatible.


that would be something like `--mcpu=i686 --mattrs=-mmx,-sse` 
and maybe more to be sure.



Other things: "Registered Targets: ... " means that maybe the 
LDC developers could add the i586 target but did not consider 
useful to add this is old processor (e.g Pentium1). For that 
you should ask them if you can and how activate the target when 
you build ldc2 on your old Geode.


ask here https://forum.dlang.org/group/ldc for better answers


Re: Build for i586

2022-07-28 Thread Alexander Zhirov via Digitalmars-d-learn

On Thursday, 28 July 2022 at 06:01:17 UTC, Alexander Zhirov wrote:

```sh
/root/usr/program/gcc/9.5.0/install/bin/cc app.o -o app 
-L/root/usr/program/ldc/1.30/install/lib -lphobos2-ldc 
-ldruntime-ldc -Wl,--gc-sections -lrt -ldl -lpthread -lm -m32

```


Even tried with such a flag separately, it still doesn't work:

```sh
# /root/usr/program/gcc/9.5.0/install/bin/cc app.o -o app 
-L/root/usr/program/ldc/1.30/install/lib -lphobos2-ldc -ldrun
time-ldc -Wl,--gc-sections -lrt -ldl -lpthread -lm -m32 
-march=geode

# ./app
Illegal instruction
```

I also tried with `i586` and `pentium` - the result is the same.


Build for i586

2022-07-28 Thread Alexander Zhirov via Digitalmars-d-learn
I did a topic a [little 
earlier](https://forum.dlang.org/thread/hfzsnagofrnlmynyz...@forum.dlang.org) about compiling a compiler for processor Geode LX800.
The bottom line is that I have a processor on which I want to 
compile the program, is an i586 architecture.


The [official 
documentation](https://www.amd.com/system/files/TechDocs/33234H_LX_databook.pdf) says that "*... the core is a combination of Intel Pentium ® processor, AMD Athlon™ processor, and AMD Geode LX processor specific instructions.*" - this means that the processor architecture is **<** `i686`. And judging by the fact that Linux gives a description when calling `uname`:


```sh
# uname -m
i586
```

This suggests that the processor is CLEARLY `i586`.
The problem is that I can't assemble the software I need for this 
processor, since it is automatically assembled for `i686`.

What have I done?
I built an `ldc` compiler on this machine:

```sh
# ldc2 --version
LDC - the LLVM D compiler (1.30.0-git-32f5a35):
  based on DMD v2.100.1 and LLVM 10.0.1
  built with DMD32 D Compiler v2.086.1
  Default target: i686-pc-linux-gnu
  Host CPU: geode
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
x86- 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
```

And when I try to compile the program through it, I create a 
binary file, but when I start it outputs **Illegal instruction**:


```sh
# ldc2 app.d
# ./app
Illegal instruction
```

Here's using the `mcpu` flag:

```sh
# ldc2 --mcpu=i586 app.d -v
binary/mnt/disc/sdb/part1/program/ldc/1.30/install/bin/ldc2
version   1.30.0-git-32f5a35 (DMD v2.100.1, LLVM 10.0.1)
config
/mnt/disc/sdb/part1/program/ldc/1.30/install/etc/ldc2.conf 
(i686-pc-linux-gnu)
predefs   LDC all D_Version2 assert D_PreConditions 
D_PostConditions D_Invariants D_ModuleInfo D_Exceptions 
D_TypeInfo X86 D_InlineAsm_X86 D_HardFloat LittleEndian D_PIC 
linux Posix CRuntime_Glibc CppRuntime_Gcc LDC_LLVM_1000

parse app
importall app
importobject
(/root/usr/program/ldc/1.30/install/include/d/object.d)
importcore.attribute
(/root/usr/program/ldc/1.30/install/include/d/core/attribute.d)
importldc.attributes
(/root/usr/program/ldc/1.30/install/include/d/ldc/attributes.d)
importcore.internal.hash
(/root/usr/program/ldc/1.30/install/include/d/core/internal/hash.d)
importcore.internal.traits  
(/root/usr/program/ldc/1.30/install/include/d/core/internal/traits.d)
importcore.internal.entrypoint  
(/root/usr/program/ldc/1.30/install/include/d/core/internal/entrypoint.d)
importcore.internal.array.appending 
(/root/usr/program/ldc/1.30/install/include/d/core/internal/array/appending.d)
importcore.internal.array.comparison
(/root/usr/program/ldc/1.30/install/include/d/core/internal/array/comparison.d)
importcore.internal.array.equality  
(/root/usr/program/ldc/1.30/install/include/d/core/internal/array/equality.d)
importcore.internal.array.casting   
(/root/usr/program/ldc/1.30/install/include/d/core/internal/array/casting.d)
importcore.internal.array.concatenation 
(/root/usr/program/ldc/1.30/install/include/d/core/internal/array/concatenation.d)
importcore.internal.array.construction  
(/root/usr/program/ldc/1.30/install/include/d/core/internal/array/construction.d)
importcore.internal.array.capacity  
(/root/usr/program/ldc/1.30/install/include/d/core/internal/array/capacity.d)
importcore.internal.dassert 
(/root/usr/program/ldc/1.30/install/include/d/core/internal/dassert.d)
importcore.atomic   
(/root/usr/program/ldc/1.30/install/include/d/core/atomic.d)
importcore.internal.attributes  
(/root/usr/program/ldc/1.30/install/include/d/core/internal/attributes.d)
importcore.internal.atomic  
(/root/usr/program/ldc/1.30/install/include/d/core/internal/atomic.d)
importldc.intrinsics
(/root/usr/program/ldc/1.30/install/include/d/ldc/intrinsics.di)
importcore.internal.destruction 
(/root/usr/program/ldc/1.30/install/include/d/core/internal/destruction.d)
importcore.internal.moving  
(/root/usr/program/ldc/1.30/install/include/d/core/internal/moving.d)
importcore.internal.postblit
(/root/usr/program/ldc/1.30/install/include/d/core/internal/postblit.d)
importcore.internal.switch_ 
(/root/usr/program/ldc/1.30/install/include/d/core/internal/switch_.d)
importcore.lifetime 
(/root/usr/program/ldc/1.30/install/include/d/core/lifetime.d)
importcore.builtins 
(/root/usr/program/ldc/1.30/install/include/d/core/builtins.d)

semantic  app
entry main  app.d
semantic2 app
semantic3 app
importstd.stdio 
(/root/usr/program/ldc/1.30/install/include/d/std/stdio.d)
importcore.stdc.stddef  
(/root/usr/program/ldc/1.30/install/include/d/core/stdc/stddef.d)
importstd.algorithm.mutation
(/root/usr/program/ldc/1.30/install/include/d/std/algorithm/mutation.d)
importstd.traits
(/root/usr/program/ldc/1.30/install/include/d/std/traits.d)
import