Questions on the SI language - page 2

 

Thank you, I love this language already.

It takes a little time to get the hang of it, the tips are useful on the subject

I don't know if it matters, but it's c instead of c++.
 
#include "pch.h"
#include <iostream>
#include <cstdlib>

using namespace std;

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

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

And this is the same, but in C style.

 

Examples, by the way, will all be from herehttps://minepy.readthedocs.io/en/latest/libmine.html

it's being ported for a warm-up

C API — minepy 1.2.4.dev documentation
  • minepy.readthedocs.io
This chapter describes the mine C library. These functions and structures are declared in the header file , located in the folder. You need to add in your C source files and link your program with . Defines¶ EST_MIC_APPROX ¶ Original estimator described in DOI: 10.1126/science.1205438. EST_MIC_E ¶ Estimator described in DOI: arXiv:1505.02213...
 
Vladimir Simakov:

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

I didn't see your post, apparently you were writing at the same time as me, I was trying to explain the same thing

This is how I learned to work with pointers 20 years ago when I was studying C++:

- declare a pointer - the pointer's value is a memory cell address

- dereferencing a pointer gives a value which is stored in a memory cell by the address equal to the pointer

- When dereferencing a pointer, exactly the number of bytes that describes the pointer type will be swallowed (written). If the pointer type is simple (int, double...), we will work with 4 or 8 bytes - it is very simple here. If we have a complex type - structure, a similar operation will be performed - work with memory cells.


approximately so, as they say "on the fingers" ))))


SZZ: Pointers to objects and functions work similarly, but function (method) calls are formed additionally, i.e. instead of working with data, the compiler will call the function when dereferencing the pointer

 
Igor Makanu:

I didn't see your post, apparently you were writing at the same time as me, I was trying to explain the same thing

This is how I learned to work with pointers 20 years ago when I was studying C++:

- declare a pointer - the pointer's value is a memory cell address

- dereferencing a pointer gives a value which is stored in a memory cell by the address equal to the pointer

- When dereferencing a pointer, exactly the number of bytes that describes the pointer type will be swallowed (written). If the pointer type is simple (int, double...), we will work with 4 or 8 bytes - it is very simple here. If we have a complex type - structure, a similar operation will be performed - work with memory cells.


approximately so, as they say "on the fingers" ))))


SZZ: Pointers to objects and functions operate similarly, but function (method) calls are formed additionally, i.e. instead of working with data, the compiler will call a function when dereferencing the pointer.

No. The function will return the pointer to the memory allocated inside the function. When dereferencing the pointer, there will be no additional function call because the pointer is the address of the first byte of the entity in memory.

When freeing memory, the memory manager will mark the memory on the reference as free + type size and that's it.

 
Vladimir Simakov:

No. The function will return a pointer to the memory, which will be allocated inside the function. And when dereferencing the pointer, there will be no additional function call because the pointer is the value of the address of the first byte of the entity in memory.

When freeing memory, the memory manager will mark the memory on the reference as free + type size and that's it.

I wrote the general principles of how pointers work,

ok, let's stop here, otherwise the topicstarter will get bogged down in discussions about who wrote and what he thought

SZS: I always say I'm not very good at explaining, here's an example of what I wrotehttps://metanit.com/sharp/tutorial/8.3.php , the Sharpe syntax works the same way

Указатели | C#
  • metanit.com
Если вы программировали на С/С++, то, возможно, вы знакомы с таким понятием как . Указатели позволяют получить доступ к определенной ячейке памяти и произвести определенные манипуляции со значением, хранящимся в этой ячейке. В языке C# указатели очень редко используются, однако в некоторых случаях можно прибегать к ним для оптимизации...
 
Maxim Dmitrievsky:
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);
}

Isn't that easier?

#python

list.sort()

See for surehttps://www.youtube.com/watch?v=vHeeXI84GIA

Stop flitting from article to article from language to language, get a grip

 
Кеша Рутов:

Isn't that easier?

#python

list.sort()

See for surehttps://www.youtube.com/watch?v=vHeeXI84GIA

Stop flitting from article to article from language to language, get a grip

Where do you think the python itself came from?

Be sure to take a look... and researched the links further, found - "IN SCHOOL MORE THAN 10 DAYS OF VIDEO LESSONS"... laughed... moved on))

 
Dmitry Fedoseev:

Where do you think the python itself came from?

Definitely looked it up... and researched the links further, found - "IN SCHOOL MORE THAN 10 DAYS OF VIDEO LESSONS"... laughed... moved on))

Well, write in C or, better, in Asembler, trading systems and machine learning. We'll talk in 100 years, in the next life, when you'll write the first prototype...


I'm not against C and ASM, the question is, for what purpose? Firewares, OS, controllers, new kernels, etc... No way, but the C application software is hard, there are no C threads, everything is different for different OSes, this is not a forum for writing firewares and viruses, for TC and MO the world standard is python, in a pinch java/sysharp. And Maxim is a well-known Internet surfer, just surfing around in search of "interesting", as a preschooler, here and there, reading abstracts, picking up smart words to appear scientific and looking for more, such activity does not end well, for a grown man, you can only fool yourself. If he ran out of sources of income and had to face LIFE, he would not even get hired at a provincial office for free and would have to go to the service sector where there is fierce competition, but he at least sobered up.

 
Кеша Рутов:

Well, write in C, or preferably in Asembler, trading systems and machine learning, we'll talk in 100 years, in the next life, when you write your first prototype...


I'm not against C and ASM, the question is, for what purpose? Firewares, OS, controllers, new kernels, etc... No way, but the C application software is hard, there are no C threads, everything is different for different OSes, this is not a forum for writing firewares and viruses, for TC and MO the world standard is python, in a pinch java/sysharp. And Maxim is a well-known Internet surfer, just surfing around in search of "interesting", as a preschooler, here and there, reading abstracts, picking up smart words to appear scientific and looking for more, such activity does not end well, for a grown man, you can only fool yourself. If he ran out of sources of income and had to face LIFE, he would not even get hired at a provincial office for free and would have to go to the service sector where there is fierce competition, but he at least sobered up.

And what don't you like about C++ since 11-th standard? I agree about C, but the modern pluses look very good. It's just that C/C++ is closer to hardware and one should keep it in mind and not just write in this style: "Hey, hardware, give me this, give me that". In the end, all this functionality either in one form or another is already available in STL, or can be implemented without any problems, but direct work with memory in all these frameworks is not certainly possible.

Reason: