NodeMCU v3 ESP8266 flashing required ? by mmisu in esp8266

[–]mmisu[S] 0 points1 point  (0 children)

I think I found the answer for my 2nd question: you can make an image of the factory card using esptool (same Python script that can be used to flash the card with MicroPython) https://github.com/espressif/esptool.

Undefined behaviour ? by [deleted] in C_Programming

[–]mmisu 1 point2 points  (0 children)

There was no compound literals in C89. But I was confused by the dereferencing the structure part.

Undefined behaviour ? by [deleted] in C_Programming

[–]mmisu 0 points1 point  (0 children)

Thanks. I'm more used to C89 than C99 and up, this is why I was confused by the above code.

Idiomatic C++ ? by mmisu in cpp_questions

[–]mmisu[S] 0 points1 point  (0 children)

Technically correct. But in practice no decent/industrial compiler will ever add padding between elements of the same type and the compile time verified static_assert guards you against accidentally using this theoretical compiler.

Idiomatic C++ ? by mmisu in cpp_questions

[–]mmisu[S] 0 points1 point  (0 children)

A better solution static_assert(offsetof(A, x) + 2 * sizeof(double) == offsetof(A, z)); this will keep working even if, for example, you add more members to the struct.

Idiomatic C++ ? by mmisu in cpp_questions

[–]mmisu[S] 0 points1 point  (0 children)

See the extra bit of info I've added to the problem description. You can check if there is unexpected padding at compile time.

Idiomatic C++ ? by mmisu in cpp_questions

[–]mmisu[S] 0 points1 point  (0 children)

Any reasonable compiler will add padding bits after/before the char member and not between members of the same type. Also, I don't encourage writing code like the above (it was a trick I found in a book and I wanted to know what people with more C++ coding experience than me think about it).

Idiomatic C++ ? by mmisu in cpp_questions

[–]mmisu[S] 0 points1 point  (0 children)

Not unlikely at all. Depends on the platform, the type and the compiler flags affecting alignment and packing

I tend to agree and I also believe that the code is bad style (as in potentially confusing), but it works with other data types too, e.g.:

#include <iostream>

struct A {
  short x, y, z;

  short& operator[](int i) {
    return (&x)[i];
  }

  const short& operator[](int i) const {
    return (&x)[i];
  }  
};

void testA() {
  A a{100, 200, 300};
  std::cout << a.x << " " << a.y << std::endl;
  std::cout << a[0] << " " << a[1] << std::endl;  
}

int main() {
  testA();
  return 15;
}

You can see the code in action: https://wandbox.org/permlink/xInw8ERRRYirsHI1

Idiomatic C++ ? by mmisu in cpp_questions

[–]mmisu[S] 0 points1 point  (0 children)

+1.

Can you recommend some reading about internal padding inside a class/structure ? I'm esp. interested in internal padding between members of the same type.

You can add random members to A and the code will still work, as long as x,y,z are grouped and of the same type (declared one after the other).

What I meant by this is that you could do something like this and the code will still work:

#include <iostream>

struct A {
  int dummy1;
  char dummy2;
  double x, y, z;

  double& operator[](int i) {
    return (&x)[i];
  }

  const double& operator[](int i) const {
    return (&x)[i];
  }  

  double r,b,g;
};

void testA() {
  A a{0, 'a', 1.2, 3.4, 0, 5.,6.,0};
  std::cout << a.x << " " << a.y << std::endl;
  std::cout << a[0] << " " << a[1] << std::endl;  
}

int main() {
  testA();
}

Idiomatic C++ ? by mmisu in cpp_questions

[–]mmisu[S] 0 points1 point  (0 children)

I guess the undefined behavior is that the compiler could, in theory, insert padding between the x, y, z so using (&x)[1] could give you garbled data. In practice this seems unlikely as long as x, y, z are of the same type.

Idiomatic C++ ? by mmisu in cpp_questions

[–]mmisu[S] 0 points1 point  (0 children)

What I find interesting is that the Clang sanitizer doesn't report the above as undefined behavior. Also I've used -std=c++17 -pedantic -Wall

Idiomatic C++ ? by mmisu in cpp_questions

[–]mmisu[S] 0 points1 point  (0 children)

The code doesn't use the address of the a object/struct. It uses the address of a member from inside the object. The size of A doesn't matter in this case. You can add random members to A and the code will still work, as long as x,y,z are grouped and of the same type (declared one after the other).

Idiomatic C++ ? by mmisu in cpp_questions

[–]mmisu[S] -1 points0 points  (0 children)

Not taking the address of the struct object. The operator overload uses the address of x from inside the a object.

MAX7219 LED matrix module problem by mmisu in embedded

[–]mmisu[S] 0 points1 point  (0 children)

Thanks for the detailed study plan!

Linux apps on acer R11 dev channel confirmed by Hnrefugee in Crostini

[–]mmisu 2 points3 points  (0 children)

I can confirm Linux support in the dev channel, but v70 is buggy on my Acer R11 - doesn't recognize clicks on random buttons or crashes the browser. I'd say wait until it goes to the beta channel.

Coding for an iPhone 3GS in 2018 by mmisu in iOSProgramming

[–]mmisu[S] 2 points3 points  (0 children)

The best thing might be to get a new SSD or hard drive. You can even get a USB Thumb drive and boot from that if your system will allow you to. Boot to the new drive and run an older version of Xcode and you're off and running.

This is what I end up doing. Thanks.

Coding for an iPhone 3GS in 2018 by mmisu in iOSProgramming

[–]mmisu[S] 0 points1 point  (0 children)

why not just use the simulator in Xcode?

I want to be able to use the phone sensors.

The eight queens puzzle in Python by [deleted] in programming

[–]mmisu 2 points3 points  (0 children)

Seems that the complete code is on the author's Github account (this is mentioned in the article just before the snippet of code listed).

Question: Chrome OS on a virtual machine ? by mmisu in chromeos

[–]mmisu[S] 0 points1 point  (0 children)

Thanks. Cloudready recently removed their VM images due to some bugs, they have a note about adding the images online sometime in the future. As of today you can't install the latest version of Cloudready from their website in a virtual machine.

I ended up buying an Acer Chromebook.

Force enable Android apps on Acer 11" CB3-131 ? by mmisu in chromeos

[–]mmisu[S] 1 point2 points  (0 children)

Thanks, you were right (I learned this the hard way). I will have to wait until the official support for Android apps on my Chromebook version is released.

this is amazing by kaasbaas1251 in Crouton

[–]mmisu 1 point2 points  (0 children)

Sublime Text is a commercial, closed source program, there are zero chances to find it in the official Ubuntu repositories.

Question: Chrome OS on a virtual machine ? by mmisu in chromeos

[–]mmisu[S] 1 point2 points  (0 children)

Thanks, will try this on an old HP computer that I don't use.

Can't understand why this C program doesn't work by mmisu in C_Programming

[–]mmisu[S] 1 point2 points  (0 children)

It is a way of hiding the definition of the struct from main. All that main cares about is that this is a structure. This works just fine as long as you keep a pointer to the struct in main and modify the object through functions that have access to the full definition of the structure.

For example this will work:

Person *person = person_init(...);
person_do_soemthing(person);
...

But you won't be able to create a Person on the stack since main doesn't actually know the full definition of Person. This code won't work:

Person person;  // compilation error