Questions on the SI language

 
void quicksort(double *a, int *idx, int l, int u)
{
  int i, m, idx_temp;
  double a_temp;

  if (l >= u)
    return;

  m = l;
  for (i=l+1; i<=u; i++)
    {
      if (a[i] < a[l])
        {
          ++m;

          idx_temp = idx[m];
          idx[m] = idx[i];
          idx[i] = idx_temp;

          a_temp = a[m];
          a[m] = a[i];
          a[i] = a_temp;
        }
    }

  idx_temp = idx[l];
  idx[l] = idx[m];
  idx[m] = idx_temp;

  a_temp = a[l];
  a[l] = a[m];
  a[m] = a_temp;

  quicksort(a, idx, l, m-1);
  quicksort(a, idx, m+1, u);
}

how does this syntax work? is the f-e within itself? 2 times as well

Also, can you recommend a good book that's informative and not too long?

I've got one.

Б. Kernighan, D. Ritchie

The C programming language.

Edition 3 revised

 

This is also possible in mql. Not every time a function is called, it is called twice more - there is a return at the beginning of the function.

It's called recursion.

https://ru.wikipedia.org/wiki/Рекурсия

https://habr.com/ru/post/275813/

 
Dmitry Fedoseev:

This is also possible in mql. Not every time a function is called, it is called twice more - there is a return at the beginning of the function.

It's called recursion.

https://ru.wikipedia.org/wiki/Рекурсия

https://habr.com/ru/post/275813/

I am rewriting one of the libraries on mql, following your advice ))

 
Maxim Dmitrievsky:

Also, advise a good book that's informative and not too long.

I read Straustrup at uni, but I don't think you need a textbook on basic language constructs, you already have programming experience, you don't need to read from scratch.

I've never written in C#, but I used to write Windows programs. When I decided to try my hand in C# the online help was very helpful, any small questions clarified, I read short articles on this resource, recursion C++ is briefly described here

https://metanit.com/cpp/tutorial/3.6.php

General C++ tutorialhttps://metanit.com/cpp/tutorial/, I doubt you'll find more concise information than on this site ;)

C++ | Рекурсивные функции
  • metanit.com
Рекурсивные функции - это функции, которые вызывают сами себя. Например, определим вычисление факториала в виде рекурсивной функции: В функции factorial задано условие, что если число n больше 1, то это число умножается на результат этой же функции, в которую в качестве параметра передается число n-1. То есть происходит рекурсивный спуск. И так...
 
Igor Makanu:

I read Straustrup at uni, but I don't think you need a textbook on basic language constructs, you already have programming experience, you don't need to read from scratch

I've never written in C#, but I used to write Windows programs. When I decided to try my hand in C# the online help was very helpful, any small questions clarified, I read short articles on this resource, recursion C++ is briefly described here

https://metanit.com/cpp/tutorial/3.6.php

I doubt you will find any more concise information than on this site ;)

You just need to understand the language. The main difficulty there is that the whole code is written through pointers and goto, and there is much unnecessary stuff with memory allocation and then deletion.

So it may be stated that mql and CY are absolutely different languages. Even such simple constructs as passing pointers instead of arrays into a function don't work here, it's very hard to rewrite.

 
Maxim Dmitrievsky:

It's easy to get into the language, the main difficulty there is that all code is written through pointers and goto, there is a lot of unnecessary stuff with memory allocation and then destruction

That's why it's obvious that mql and CY are absolutely different languages. Even such simple constructs as passing pointers instead of arrays into a function don't work here, it's very hard to rewrite.

That's what makes C++ so interesting - it's based on working with pointers. The processor doesn't know names of identifiers (names of variables), it only knows relative data offsets (links to memory addresses) and the referenced data needs to be typed - that's what a pointer does - it describes the type of data and where the data is stored in memory


MQL is really a different language


pointershttps://metanit.com/cpp/tutorial/4.1.php

C++ | Что такое указатели
  • metanit.com
Указатели представляют собой объекты, значением которых служат адреса других объектов (переменных, констант, указателей) или функций. Как и ссылки, указатели применяются для косвенного доступа к объекту. Однако в отличие от ссылок указатели обладают большими возможностями. Для определения указателя надо указать тип объекта, на который указывает...
 
Igor Makanu:

That's what's interesting about C++ - it works with pointers, all the flexibility of the language is based on working with pointers - aka full imitation of working with processor memory, processor doesn't know names of identifiers (variable names), it knows only relative data offsets (in fact references to memory addresses) and data by reference must be typed - that's what a pointer does - it describes data type and location where data is stored in memory


MQL is really a different language


pointershttps://metanit.com/cpp/tutorial/4.1.php

Yes, thanks, I am already familiar with pointers, and the book has

The site is handy, by the way, added it to my favorites.

here's a good video lecture course for the lazy, from c to cp


 

Here is an example from the library header:

structures are created with pointers to something unclear (apparently, they are arrays that don't exist yet), then I understand that a ...er...variable of this structuremine_score; with the same name is declared?

typedef struct mine_score
{
  int n;      /* number of rows of M */
  int *m;     /* number of cols of M[i] for each i */
  double **M; /* the (equi)characteristic matrix */
} mine_score;

we'll have to deal with that too

and then a f-i is declared which will write its result directly into the memory space of this variable?

mine_score *mine_compute_score(mine_problem *prob, mine_parameter *param);
 
Maxim Dmitrievsky:

Here is an example from the library header:

structures are created with pointers to something unclear (apparently, they are arrays that don't exist yet), then I understand that a ...er...variable of this structuremine_score; with the same name is declared?

we'll have to deal with that too

and then we declare a f-that will write its result directly to this variable's memory location?

No, the data type declared here is mine_score, which is a mine_score structure.

And the function returns a pointer to this structure, which will be created inside this function. Accordingly, the purpose of the function is to create an entity of type min_score and transfer ownership of it to the scope of the function call.

 

Maxim Dmitrievsky:

this will also have to be dealt with

and then a f-i is declared which will write its result directly into the memory space of this variable?

I forgot typedefs a long time ago, thanks MQL help to remember these cumbersome constructions)), apparently it's just a declaration ofmine_score type, which is a structure and structure description was "pasted" into type definition ( typedef ) , but I could be wrong, here is a similar question discussed and quite detailed explanation:

http://qaru.site/questions/13054/typedef-struct-vs-struct-definitions


Maxim Dmitrievsky:

and then you declare a f-i that will write its result directly into the memory space of this variable?

In C++, the programmer is in charge of memory allocation, so if the result of a function returns amine_score* pointer, the one who receives this pointer must allocate memory, i.e. it's not a variable but a pointer to the data

Определение typedef struct vs struct
  • 2009.11.04
  • user69514
  • qaru.site
Я новичок в программировании на С, но мне было интересно узнать, какая разница между использованием при определении структуры или использованием . Мне кажется, что нет никакой разницы, они достигают той же цели.
 
Igor Makanu:

I forgot typedefs a long time ago, luckily MQL help me remember those cumbersome constructions)), it seems to be just a declaration of typemine_score, which is a structure and structure description was "pasted" into type definition ( typedef ) , but I could be wrong, here is a similar question discussed and quite detailed explanation:

http://qaru.site/questions/13054/typedef-struct-vs-struct-definitions


In C++, memory allocation is the responsibility of the programmer, so if the result of a function returns amine_score * pointer, whoeverreceives that pointer should allocate the memory, i.e. it's not a variable but a pointer to the data

#include "pch.h"
#include <iostream>

using namespace std;

int* Foo(int i)
{
        int* x = new int(i);
        return x;
}

int main()
{
        int* x = Foo(5);
        cout << *x;
        delete x;
        return 0;
}

I allocated memory inside the function and freed it in the scope of the variable I passed the reference to.

Reason: