this is a very good blog post՝ back to basics about strings in C and Pascal. i suggest you to read it, and now i’ll tell you something else:
in Oberon, Wirth decided to give up on Pascal strings, and use zero terminated strings.
however, there is no need to run by the whole array to find out the length of the string. we don’t even need to have a separate field that holds the length՝ compiler knows the length of the static string.
thus it can do compile time tests. for example we have the following Oberon source՝
MODULE tst;
IMPORT Out;
VAR i: SHORTINT;
str: ARRAY 1024 OF CHAR;
BEGIN
FOR i := 0 TO LEN(str) DO
Out.Int(i, 0); Out.Ln
END;
END tst.
lets try to compile it՝
[2020-09-02 16:00:20] $ voc -m tst.Mod
tst.Mod Compiling tst.
9: FOR i := 0 TO LEN(str) DO
^
pos 102 err 113 incompatible assignment
Module compilation failed.
[2020-09-02 16:00:21] $
voc compiles Oberon source to C, which is very good to illustrate what happens. if we have՝
str: ARRAY 16 OF CHAR;
then the output C code will be՝
static CHAR tst_str[16];
nothing more։ no field for the length.
still, this՝
FOR i := 0 TO LEN(str) DO
will translate to՝
tst_i = 0;
while (tst_i <= 16) {
as i said we know the length at compile time. doesn’t matter if you generate C or assembly, you already know the number, you can put the number to the output assembly code as well.
when we write a function which receives strings, we should not knowt the length of the received string, we just use ARRAY OF CHAR
as an argument՝
MODULE tst2;
PROCEDURE addStrs(VAR a, b: ARRAY OF CHAR);
BEGIN
(* do smth useful here *)
END addStrs;
PROCEDURE test*;
VAR
s0: ARRAY 32 OF CHAR;
s1: ARRAY 64 OF CHAR;
BEGIN
addStrs(s0, s1);
END test;
END tst2.
therefore C code will be՝
static void tst2_addStrs (CHAR *a, ADDRESS a__len, CHAR *b, ADDRESS b__len)
{
/* here we think we can do smth useful */
}
void tst2_test (void)
{
CHAR s0[32];
CHAR s1[64];
tst2_addStrs((void*)s0, 32, (void*)s1, 64);
}
as we see՝ the function also gets the length of strings. and if we do LEN(a)
we get the length without any calculations.
now let’s see how dynamic strings work՝
MODULE tst3;
PROCEDURE addStrs(VAR a, b: ARRAY OF CHAR);
BEGIN
(* do smth useful here *)
END addStrs;
PROCEDURE test*(i: INTEGER);
VAR
s: ARRAY 32 OF CHAR;
ps: POINTER TO ARRAY OF CHAR;
BEGIN
NEW(ps, i);
addStrs(s, ps^);
END test;
END tst3.
now we hase a static string՝ s and we allocate a dynamic string with its pointer ps
.
lets assume we don’t know the size of ps^
string (^
means dereference) and we will receive the length of the allocated string as a function argument. it is not known at compile time.
first function remains unchanged, second function gets translated like this՝
static void tst3_addStrs (CHAR *a, ADDRESS a__len, CHAR *b, ADDRESS b__len)
{
/* do smth useful here */
}
void tst3_test (INT16 i)
{
CHAR s[32];
struct {
ADDRESS len[1];
CHAR data[1];
} *ps = NIL;
ps = __NEWARR(NIL, 1, 1, 1, 1, ((ADDRESS)(i)));
tst3_addStrs((void*)s, 32, (void*)ps->data, ps->len[0]);
}
the _NEWARR
is a bit more complicated function, which is a part of the runtime.
but we can understand what it does՝ it allocates a space in the heap, and the pointer ps
we get now points to the struct
, which has a data
field and len
field.
this is a runtime information, and in this case we have to keep a separate field for the length of the string.
that’s it.
#oberon #c #pascal #wirth #programming #programming-languages #programming_languages #design #implementation #vishap #voc #compiler #compilation #strings #string #heap #stack #storage #storage-management #storage_management #length
Modula and Modula-2 went nowhere not because they’re particularly high level languages (they’re not much higher than C!) but because they didn’t have a quasi-free operating system spreading like a virus to bolster their popularity. At the time Unix was almost unique in being a semi-capable operating system written in a portable language that wasn’t wrapped up in billions of proprietary licensing arrangements (because AT&T didn’t notice there was a potential market for it until after the cat had escaped the bag).
#modula #modula-2 #modula2 #c #programming-languages #programming_languages #unix
http://simula67.at.ifi.uio.no/50years/ 50 years anniversary of Simula, the first object-oriented programming language.
#simula #programming-languages #programming_languages #programming
C, Rust, Pascal and Go are the best in terms of energy consumption!
https://jaxenter.com/energy-efficient-programming-languages-137264.html
#golang #c #rust #pascal #energy #programming-languages #programming_languages #programming
TIL swift allows emojis as variables
yes, that’s a very useful feature of the modern languages, and unicode will allow to use one exact symbol instead of =>, <=, and most importantly ==, by mapping keys, so that we’ll avoid problems like if (a=b)
which is always true. (:
#programming #programming-languages #programming_languages #emoji #unicode
if you are forced to use a subset of the language due to its complexity, then they failed to offer an useful language.
from #oberon room on freenode.
#programming #programming-languages #programming_languages #chat #talk
today we were discussing different spacecraft accidents caused by/related to software, discussed Arian-5 case, and I remembered a Soviet case, where there was a problem with decimal separator and Fortran compiler. Decimal separator in USSR was comma, but in Fortran code it should be the dot.
Also, Fortran compiler did not consider using comma instead of the dot as an error, but as different code. And my friend said - the same is possible to do in C++ - and sent me the illustration.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
if (1,2!=1.2)
{
cout << (1,2) << endl;
}
return 0;
}
if you run it, you’ll get
Hello World
2
(:
#safety #programming #mistakes #safe #c++ #code #example #programming-languages #programming_languages #arian #fortran #source
C++ is a horrible language. It’s made more horrible by the fact that a lot of substandard programmers use it, to the point where it’s much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do nothing but keep the C++ programmers out, that in itself would be a huge reason to use C.
Linus Torvalds, here.
#linus #linus_torvalds #git #programming_languages #programming-languages #c++ #c #programming
critics of go http://dtrace.org/blogs/wesolows/2014/12/29/golang-is-trash/
#critics #golang #google-go #go #programming #programming-languages #plan9 #assembler #language #design
Running 4 copies of an operating system at once
Dick explained to me that they were using an operating system from a company called Telesoft. Telesoft, headed by UCSD Pascal author Ken Bowles, was building an Ada compiler on top of its ROS (Renaissance Operating System) product. He told me (and I remember this clearly) that they had the operating system running in single user mode but that they wanted to run it in multi-user mode. At that point I was barely 21 years old. I had written a whole bunch of system-level 6502 assembler code and I had a really good ground-up understanding of the way that contemporary computer hardware worked. After studying the manual for the SUN board, I decided that I could simply break the 2MB of physical memory in to 4 chunks of 512KB each and run 4 copies of the operating system, gaining control via interrupts and device drivers.
#6502 #telesoft #pascal #ada #operating-systems #ucsd-pascal #compiler #ros #renaissance-operating-system #programming #history #computing #programming-languages #sun #intellimac #unix #msx #motorola68000 #68000 #68k #motorola-68k #ibm #stanford #research #memory
New edition of Wirth’s book Project Oberon is out. It describes not only built from scratch software(entire operating system and compiler), but design of the hardware as well.
The vast complexity of popular operating systems makes them not only obscure, but also provides opportunities for “back doors”. They allow external agents to introduce spies and devils unnoticed by the user, making the system attackable and corruptible. The only safe remedy is to build a safe system anew from scratch.
http://www.inf.ethz.ch/personal/wirth/ProjectOberon/index.html
#oberon #wirth #niklaus-wirth #risc #programming #fpga #books #programming-languages #compilers #operating-systems #compiler #freedom #design #security #privacy #surveillance #reliability
https://groups.google.com/forum/#!topic/comp.lang.oberon/8Bmb20Ds8Cg
#programming #usenet #1993 #oberon #c #libc #ulms-oberon-compiler #programming-languages #hello-world #write #printf #setlocale
So #go is 16th, thus it took place in top 20 #github languages.
http://adambard.com/blog/top-github-languages-for-2013-so-far/
However last year it was at 13th place. Anyway, I think that’s a great achievement for #golang. #google-go #go-lang #programming #programming-languages #փաստորեն
On the X axis you see the number of threads that the program creates. On the Y axis you see the arithmetic mean of the run time over 10 runs. The green line is Haskell, the red line is C. Haskell is almost 10 times faster. Control.Concurrent kicked pthreads’ ass, leaving it no chances.
http://10098.arnet.am/?p=147 #haskell #threads #c #comparison #programming #pthread #benchmark #programming-languages
The #libc is certainly not a good guide:
(Please note that I do not want to bash Ritchie, Kernighan etc. The libc is #history and should be taken as such… It is time to abandon #C and the libc and it does not help to place other systems on top of this historic relic.) #programming-languages https://comp.lang.oberon.narkive.com/Vb26nQgd/some-ideas-on-eth-oberon-linux-c-relationship http://groups.google.am/group/comp.lang.oberon/browse_thread/thread/ffe11b45037375e0/e8b65d37114d4931?hl=hy&ie=UTF-8&oe=utf-8&q=andreas+borchert+c+interfaces#e8b65d37114d4931
Jeder dritte #Deutsche verfügt über Kenntnisse in einer #Programmiersprache http://www.heise.de/newsticker/meldung/Bitkom-Jeder-dritte-Deutsche-verfuegt-ueber-Kenntnisse-in-einer-Programmiersprache-1716836.html?view=zoom;zoom=1 #programming-languages #programming #germany #ծրագրավորում #ծրագրավորման֊լեզուներ #լեզուներ #Գերմանիա #մարդիկ