dev notes thread

Posts

I'm monitoring this thread.

Quick contribution with a C hack

//Given an array
int a[5];

// This line is correct
int b = a[1];

// And this line is correct too
int c = 1[a];

This is because of how the compiler transforms a[1] to *(a + 1) and *(a + 1) is equivalent to *(1 + a)

KuroAku wrote
//Given an array
int a[5];

// This line is correct
int b = a[1];

// And this line is correct too
int c = 1[a];

This is because of how the compiler transforms a[1] to *(a + 1) and *(a + 1) is equivalent to *(1 + a)

Thats interesting as fuck but holy shit never do that in serious code. (I wouldn't use C in serious code anyway...)

RX14 wrote

(I wouldn't use C in serious code anyway...)

I am hurt

malmon wrote
RX14 wrote

(I wouldn't use C in serious code anyway...)

I am hurt

It's too easy to make mistakes in C when languages like Rust exist. If what you're doing isn't systems programming, languages like Crystal shine.

RX14 wrote
malmon wrote
RX14 wrote

(I wouldn't use C in serious code anyway...)

I am hurt

It's too easy to make mistakes in C when languages like Rust exist. If what you're doing isn't systems programming, languages like Crystal shine.

Aren't most hardware drivers and firmware written in C? Seems pretty serious to me 😛

malmon wrote
RX14 wrote
malmon wrote
RX14 wrote

(I wouldn't use C in serious code anyway...)

I am hurt

It's too easy to make mistakes in C when languages like Rust exist. If what you're doing isn't systems programming, languages like Crystal shine.

Aren't most hardware drivers and firmware written in C? Seems pretty serious to me 😛

You can write a firmware or a driver in any language that let's you use the same ABI as the platform. You can write a Linux kernel driver in Rust if you like. Or even in Go I think it will be possible too.

KuroAku wrote
malmon wrote
RX14 wrote
malmon wrote

I am hurt

It's too easy to make mistakes in C when languages like Rust exist. If what you're doing isn't systems programming, languages like Crystal shine.

Aren't most hardware drivers and firmware written in C? Seems pretty serious to me 😛

You can write a firmware or a driver in any language that let's you use the same ABI as the platform. You can write a Linux kernel driver in Rust if you like. Or even in Go I think it will be possible too.

Though C does have the advantage of having a compiler on virtually any platform anyone might find themselves working on

malmon wrote
KuroAku wrote
malmon wrote
RX14 wrote

It's too easy to make mistakes in C when languages like Rust exist. If what you're doing isn't systems programming, languages like Crystal shine.

Aren't most hardware drivers and firmware written in C? Seems pretty serious to me 😛

You can write a firmware or a driver in any language that let's you use the same ABI as the platform. You can write a Linux kernel driver in Rust if you like. Or even in Go I think it will be possible too.

Though C does have the advantage of having a compiler on virtually any platform anyone might find themselves working on

That's why C is still the king on systems programming

malmon wrote
RX14 wrote
malmon wrote
RX14 wrote

(I wouldn't use C in serious code anyway...)

I am hurt

It's too easy to make mistakes in C when languages like Rust exist. If what you're doing isn't systems programming, languages like Crystal shine.

Aren't most hardware drivers and firmware written in C? Seems pretty serious to me 😛

Just because C is a serious language, or that others use it for serious code doesn't mean i would use it for serious code (unless I have to) now that rust is mostly stable.

4 months later

If you're getting a load of garbage between lines on a serial connection, check to see exactly how much of the string you're sending.

i.e., If you tell it to send 32 bytes, but there are only 16 characters in the string, garbage will await you on the other side.

10 days later
char rawdata = {0x12, 0x4E, 0x92};
int16_t tempData = (rawdata[1] << 8) | (rawdata[2]);

rawdata[1] and rawdata[2] are cast as int16_t before the bitwise operations are carried out!

Should be:

int16_t tempData = (rawdata[1] << 8) | (rawdata[2] & 0xFF);