Ever wanted to see "Hello World" Segment Fault?

#include <stdio.h>
#include <unistd.h>

#define MSGLEN 13
#define MSG    'Hello World!\n\0'

#define print(msg) write(1, msg, MSGLEN); 
#define sys() _exit(0)

int main(void) 
{
    print(MSG);
    sys();
}

Run that on http://s-macke.github.io/jor1k/demos/compile.html?user=CUllppsMAz

PS: Yes I know that is very janky code; that’s the point :wink:

#define MSG "Hello World!\n\0"

go figure you’d catch the trick :wink:

#include <unistd.h>

#define MSG    "Hello World!\n\0"

#define print(msg) write(1, msg, (unsigned)sizeof(msg)); 
#define sys() _exit(0)

int main() 
{
    print(MSG);
    sys();
}

I have spent more years dodging C bullets than I care to remember.

3 Likes

This is one reason I am learning Rust. The compiler catches an amazing amount of bugs. The language doesn’t allow things like many things pointing to and modifying the same part of memory. You have to either give that memory or allow something to borrow it through a reference and you can’t borrow twice at the same time.

The system is designed to be memory safe, and it does not permit null pointers, dangling pointers, or data races in safe code.[28][29][30][31] Data values can only be initialized through a fixed set of forms, all of which require their inputs to be already initialized.[32] To replicate the function in other languages of pointers being either valid or NULL , such as in linked list or binary tree data structures, the Rust core library provides an option type, which can be used to test if a pointer has Some value or None .[29] Rust also introduces added syntax to manage lifetimes, and the compiler reasons about these through its borrow checker .

All without a Garbage Collector

1 Like

Yes … all languages suck …

From that link …

  • Java sucks because Overly verbose.
  • XML sucks because its too verbose, too hard for programs to parse, and to hard for people to read.
  • Go sucks because To get a string’s true length, you have to use the well-named but horribly verbose library function
  • Rust sucks because Overly terse named types and keywords that don’t communicate their purpose, like Vec and Cell .
1 Like

same can be said about Go. Plus it has a “web framework” built-in by default

Some of the features that are great about Go:

  • Static code analysis
  • Built-in testing and profiling framework
  • Race condition detection
  • Go’s syntax includes changes from C aimed at keeping code concise and readable
  • types and structs have abstraction and interfaces
  • structures support json out of the box

I will have to check out Go … it does have a Garbage Collector however.

I recall there is an overabundance of shifting (like C and C++). I find that alone to be a barrier / steepen the learning curve with programming languages.

The syntax is wickedly bizarre.

I do like having test cases in the same source file and the overall concept is compelling.

The lack of mature libraries put me off.

Excellent! Please, let us know how that goes.

Yes … all languages suck …

Lets add a few:

  • Assembly sucks because way to turse and close to the metal to do anything highlevel.
  • C/C++ … Pointers, buffer overflows, compiler hell, optimization hell
  • Javascript because framework hell
  • Python opinionated tabs
  • Perl bulky modules and regex that is inconsistent plus poor performance compared to shell or python.
  • Pascal well already documented by better Programmers than any of us.
  • Basic sucks because one is screaming with line numbers; 20 goto 10 loops. Might as well use assembly plus half the time one does.

I’ll leave it here because I could do this all day

Once I get most of it down and a bit of experience with it… I MAY teach a class on the basics

2 Likes

I WILL attend that class.

1 Like