"Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearC_
Segmentation fault for a valid program?

In the K.N.King book, there's an example: ::: spoiler **viewmemory.c** ```c /* Allows the user to view regions of computer memory */ #include <stdio.h> #include <ctype.h> typedef unsigned char BYTE; int main(void) { unsigned int addr; int i, n; BYTE *ptr; printf("Address of main function: %x\n", (unsigned int) main); printf("Address of addr variable: %x\n", (unsigned int) &addr); printf("\nEnter a (hex) address: "); scanf("%x", &addr); printf("Enter number of bytes to view: "); scanf("%d", &n); printf("\n"); printf(" Address Bytes Characters\n"); printf(" ------- ------------------------------- ----------\n"); ptr = (BYTE *) addr; for (; n > 0; n -= 10) { printf("%8X ", (unsigned int) ptr); for (i = 0; i < 10 && i < n; i++) printf("%.2X ", *(ptr + i)); for (; i < 10; i++) printf(" "); printf(" "); for (i = 0; i < 10 && i < n; i++) { BYTE ch = *(ptr + i); if (!isprint(ch)) ch = '.'; printf("%c", ch); } printf("\n"); ptr += 10; } return 0; } ``` ::: For some reason, when I try to enter addr variable address as the parameter, it has a segmentation fault error. However, in the book's example and the screenshot from this [site in Hangul](https://ziegler.tistory.com/84), there's no such error? When I try using `gdb` to check the issue, here's what I get: :::spoiler gdb ```console $ gdb ./a.out --silent Reading symbols from ./a.out... (gdb) run Starting program: /home/<username>/Desktop/c-programming-a-modern-approach/low-level-programming/a.out [Thread debugging using libthread_db enabled] Using host libthread_db library "/gnu/store/zvlp3n8iwa1svxmwv4q22pv1pb1c9pjq-glibc-2.39/lib/libthread_db.so.1". Address of main function: 401166 Address of addr variable: ffffd678 Enter a (hex) address: ffffd678 Enter number of bytes to view: 64 Address Bytes Characters ------- ------------------------------- ---------- Program received signal SIGSEGV, Segmentation fault. 0x000000000040123a in main () at viewmemory.c:31 warning: Source file is more recent than executable. 31 printf ("%.2X ", *(ptr + i)); (gdb) ``` ::: What is going on? By the way, I am using Guix, if that matters in any way. Here's the output for `ldd`: :::spoiler ldd ```console $ ldd ./a.out linux-vdso.so.1 (0x00007ffecdda9000) libgcc_s.so.1 => /gnu/store/w0i4fd8ivrpwz91a0wjwz5l0b2ralj16-gcc-11.4.0-lib/lib/libgcc_s.so.1 (0x00007fcd2627a000) libc.so.6 => /gnu/store/zvlp3n8iwa1svxmwv4q22pv1pb1c9pjq-glibc-2.39/lib/libc.so.6 (0x00007fcd2609c000) ``` :::

2
1
"Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearC_
Jump
How is MS-DOS able to store seconds in just 5 bit-field?
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    I don’t know the specifics, but why would 5 bits be a problem on a 16bit machine?

    Because I'm assuming that there's only 16 bits, right, and hence these have to be divided between hours, minutes and seconds:

    • 5 bits for the hours (2^5^ = 32, to represent numbers from 0-23)
    • 6 bits for the minutes (2^6^ = 64, can represent numbers from 0-59)
    • the 5 bits for the seconds (2^5^ = 32, can only represent numbers from 0-31, what about seconds 32-59?)

    5 + 6 + 5 = 16 bits in total. This is why the last one makes no sense, unless the timeformat precision was restricted to 2 seconds?

    2
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearC_
    Jump
    How is MS-DOS able to store seconds in just 5 bit-field?
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    But during the release of MS-DOS, there were only 16-bit microprocessors, right? 32-bit x86 processors came way later around 1985, I think?

    1
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearC_
    Jump
    How is MS-DOS able to store seconds in just 5 bit-field?
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    This seems to be the likely answer. I'm assuming that it has something to do with the technological limitation of 16 bit. 1981 saw the first 32-bit non-x86 microprocessor (Intel iAPX 432), and MS-DOS was released for 16-bit in mind, like the 8086. Perhaps, the highest size of the integer was limited to 16 bit as well, and with that in mind, they had to make sure to create a non-padded struct for time, in which the hour were allotted 5 bits (= 32 ≈ 24hour), minutes were allotted 6 bits (= 64 ≈ 60mins). The last remaining 5 bits were assigned to seconds, and with the remaining bit-fields, the best precision they could come up with gave a 2-second interval. Is that a fair reasoning?

    2
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearC_
    How is MS-DOS able to store seconds in just 5 bit-field?

    Second representation requires at least 6 bits to represent numbers between 0 to 59. But 5 bits are not just enough - 2^5^ = 32, which can only represent from 0 up to 31 seconds. According to K.N. King: >You may be wondering how it 's possible to store the seconds - a number between 0 and 59 in a field with only 5 bits. Well. DOS cheats: it divides the number of seconds by 2, so the seconds member is actually between 0 and 29. That really makes no sense?

    5
    15
    "ai" hucksters lack the human experience
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    Apparently, AI is a closeted christofash, as long as you're good at jail-breaking the stupid generative black-box - you know, filters by the employees who have no moral integrity.

    No, I'm not even kidding - ask it to draw "Man flying while shitting on toilet", and the result would definitely be either an Indian or an Middle-Eastern. As if it wasn't preached about heavily, bias in AI is a feedback-effect - it starts small, but keeps believing in falsified data, as more and more AI filth keeps polluting the internet.

    This particular example isn't AI, but an actual system used by the US police department. Black neighborhoods have more likelihood of criminals - because those police were not deployed to the white ones, the report keeps coming in positive, and this loop "confirms" the lies that black people kill other black people.

    17
  • Are NixOS / Guix SD / Gentoo good choices for development?
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    Since there's no answer from Guix users over here, well, I use Guix as my main distro. The language choice is superior to Nix's half-Haskell DSL. However, the bigger issue with Guix is the lack of maintainers. NodeJS hasn't been updated since the last five year and Zig lacks a lot of packages. Another big issue is the centralized GNU server, which can fail at any moment. Their servers are all located in either the USA, or Europe, and for Asia, downloading NARs with such slow speed is a pain in the ass.

    9
  • Are NixOS / Guix SD / Gentoo good choices for development?
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    No FHS compatibility seems fine but certain programs require it and don’t have nix native workarounds.

    Nix, as well as Guix, both have the option to enable FHS emulation to resolve this issue.

    3
  • Are NixOS / Guix SD / Gentoo good choices for development?
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    Things like developer-only scripts with hardcoded #!/bin/bash shebangs are more likely to break on NixOS than they would on a conventional Linux distro with Nix installed.

    This can be substituted or patched to #!/usr/bin/env bash - it's an easy fix. The actual issue is contamination of environment, caused by mismatching glibc-locale between the host package and third-party package.

    3
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearC_
    Jump
    What exactly is linkage in C?
    "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearC_
    What exactly is linkage in C?

    It looks very similar to scope, so I really don't understand the difference. What makes storage classes different from each other? How is `auto` not the same as `static`, `extern` or `register`?

    3
    2
    IF ONLY
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    The duality of the previous and current post is...confusing. I was under the assumption that Poland is a Christo-fascist state? Or is it not?

    8
  • Russian language is as much a part of Ukraine as Ukranian is. You won't see many in the media calling it Kyiv before Ukraine turned nationalist under Poroshenko
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    Because the script for English is stupid, and I'm not sure why it hasn't been phased out with something like Shavian. "a" can have the "ah" sound (alternative), the "ae" (amazing) sound and the "eh" sound (bad). Similarly, "e" can have the "ae" sound (elephant), "aih" sound (eye) and the "i" sound (economy).

    On a similar note, karma (कर्म) is not spelt as car-muh, it's cur-mha.

    15
  • If Palestine got to have its own recognized (by everyone including Israel) and sovereign state, what other different current nation would it most likely resemble?
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    It's not a success. Two-state solution is a failure. Be it India-Pakistan, East-West Germany, North-South Korea or Sudan-South Sudan.

    As someone from India, the two-state solution for India-Pakistan was a massive disaster. One of the worst man-made catastrophe. Rape, murder and violence between different ethnic groups, it was horrible. People were forcibly displaced to the other side of the country, leaving behind their ancestral village and belongings. This destroyed their culture and their language, stripped their identity.

    These states were divided to satisfy the egoes of the two major political dynasts, Nehru and Jinnah, and as typical of pretend-socialist liberals, they were supported by the Hindu Mahasabha and the All India Muslim league.

    Pakistan forced the use of Urdu, an Indian language, because their native languages had Devanagari-resembling script, and for that strong Muslim identity they went for a language with a Farsi script.... except that the language was Khadi Boli (a language from UP) with borrowed Farsi words.

    Well, what about India? They went ballistic sub-nationalist. State majoritarians forced language on vulnerable groups, including mine (obligatory middle-finger to the Basel Mission and Kannada chauvinists).

    Later, Pakistan's ethnic cleansing and rape of Bengalis, especially Hindus in East Pakistan (East Bengal) backfired, and the country broke into three. Cut to 2024, the people of Kashmir suffer even to this day.

    If only the Indian communists from the HSRA had not been betrayed by the INC, a greater India with none of the communal B.S. would have existed. There would have been no Hindutva or Deobandi extremists jump around and squirming like cockroaches. And we have two countries armed to the brim with nuclear weapons.

    21
  • If Palestine got to have its own recognized (by everyone including Israel) and sovereign state, what other different current nation would it most likely resemble?
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    Economically, somewhere between Qatar and Lebanon. Palestine's sea near Gaza has a rich source of oil. They also allow ships to cross through, which is a nice source of income. Culturally, they probably have something in common with the Lebanese and Egyptians.

    23
  • I have no idea why I am wasting my time and learning C...
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    I've not worked since the end of Jan 2023, and that was a crappy internship with low salary for which I didn't get any "certificate" or proof of claim. I've graduated almost two years ago with no job. Half-assed my way over libvulkan to create a simple 2D engine, didn't learn shit. Did some open-source contributions to GitLab with Ruby, that also didn't benefit me, because contributions have low value in CV, and recruiters don't seem to give a fuck. Also maintaining a few packages on Guix atm, but no one probably cares about Scheme. Did a few low-quality projects on ExpressJS, NextJS and Svelte.I haven't applied anywhere because I have failed take-home tasks on Flask/Django/other mainstream framework miserably, and it has tanked my confidence. Rest of the so-called interns are scammers demanding that I pay them to work. Yes, you read it right, not paid work, pay-to-work. The job market has still not recovered.

    10
  • Well, at this point, I don't even know what to learn for getting an entry level CS job...so C is it. Reached chapter 17 of K.N.King's C99, maybe read a little bit of C2x and C2y specifications, then I'll probably start reading John Calcote's Autotools and then metalanguage99. And I bet they won't help me for my early career in any way or form.

    32
    9
    This AI Startup "Copied" an Open-Source Project and Got Half a Million Dollar Funding by Y Combinator
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 96%

    Scriptkiddies doing the bare-minimum to profit over other's hard-work. They're not going to survive, because they don't know shit about the internal workings of their product, they won't be able to scale it quickly, and sooner or later, they'll run out of money, if it's not the poor publicity killing their product.

    90
  • What is the worst thing your parents ever did to you?
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    I was going to write a lot of stuff about my own experience, but then I decided that it wasn't worth writing and getting my identity exposed, so I'll say "same", minus the disowning part, because I come from a collectivist society. My failure as an mid-20s adult is theirs to blame, because that's how broken I am, and I still can't cope with the past. Tough-love my ass.

    10
  • I am become unemployed, collector of benefits
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    velox_vulnus
    Now 100%

    I am unemployed, and I still don't collect benefits, because it's just way too low, and it's not worth dealing with the bureaucratic complexity and corruption.

    2
  • "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearPR
    How do modern languages deal with prototyping and modules internally?

    In my journey to learning C, I've come across header files, which are used to (I'm assuming) define a prototype for the source file, as well as structure modules. This feature, in my opinion, is pointlessly not just redundant, but possibly a source for pitfall. The same information can probably be extracted from the source code, if not for the restrictions of the language specification in C. Say, if I have a GTK project, I will have to use the preprocessor directive, that will require the use of GTK headers that look something like `#include <gtk/gtk.h>`, and they're usually in the system path. How do modern languages, like Rust, Zig or Go deal with this situation, where shared libraries are used?

    9
    6
    "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearC_
    `#if` vs `#if defined` vs `#ifdef` directives - how are they different from each other?
    11
    3

    Because I think that it has been appropriated. Bandhani is a traditional tie-dye technique, with deep cultural and historial significance for the Rajasthani, even extending to Sindhi and Marwari sub-groups in the west of India and east of Pakistan - who comprise of nomadic and semi-nomadic artisans. The word 'bandhan/bandhana' can have several meanings depending on the context - knot, relation(ship), or kerchief - they're all related to each other, in the sense that this piece of clothing signifies relationship, and can be tied to the end of one's cloth - just in the same way you can "build" a "building" in English, if that makes sense. One of the most identifiable parts of the bandhani is the parsely and floral pattern, as well as the use of non-pastel, dark dyes. Now, I am neither a Rajasthani, nor from the north-western parts of India or eastern part of Pakistan, so it should be obvious that I don't know much about them. Maybe some information over here is not true - and I'd appreciate correction. Personally, I feel like it is an extreme case of cultural appropriation in the sense that: - the culture behind it has been erased, or people don't bother doing enough basic research behind them - it has been commodified and mass-produced as a fashion trend, which is disrespectful to the people, and has harmed their livelihood severely - the patterns have a deep cultural, religious and social significance, so do the colors, and using them trivially again erases the original meaning behind them The bandana culture (at least from my stereotype of American media) has been stolen collectively on different occasions by multiple subcultures - the hippies, the bikers, white supremacists, cowboys, gang members, black rights activists and even antifa/anarchists members, shifting the original symbolism from that of familial collectivism to something that is representative of rejection of government authority. Unfortunately, as a very vulnerable group, they don't have the voice to raise against this injustice, because obviously when basic needs are not met, people tend to ignore the erasure of their own identity and culture, and try to survive with what they can. The place that they live in is the antipode to the American continent, and obviously, that region does not receive a lot of attention, as opposed to western cities.

    16
    2

    Saw a "performative" animal rescue video where a young lad was harassing a really old, poor Rajasthani woman of nomadic origin, perhaps from a very vulnerable, and extremely backward scheduled tribe, whose culture very much resemble with the Roma people, (perhaps it is because Rajasthan/Sindh is where the Romas migrated from almost a few thousand years ago, so it makes a lot of sense). In this particular instance, she had a snake with herself, and what she would do is sell a pseudo-scientific drug/herb-mixture, claiming that this saves your from the bite of an Indian cobra. She would let the snake bite her - well, here's the reality - the snake had it's fangs removed. The snake can not survive in the wild now, which sucks. I ~~condone~~ condemn the exploitation of animals too, as well as this old lady's behavior, but how is this fair? This young lad comes from a society of high privilege and caste. Dad is probably a government civil servant, mom is a doctor. Grand parents probably one of those freedom fighters from India. So this kid is probably loaded with old money - he and his kids will never have to worry about working for their entire lives, and they'll still make money passively. Seeing from a colonialist lens, this looks like intersectional imperialism to me, in this instance, brown imperialism (which I've talked about before; remember linguistic and cultural imperialism of majoritarian culture?). The boy "saved" the snake, but at the cost of letting these vulnerable people starve, and does he provide an alternative for her livelihood? She's probably de-fang another snake, albeit with a lot of difficulty. Alternatively, there exists a few illegal night-club party bars out here in India for the ultra-rich, where they use small doses of snake toxins to get a high - I am not really sure how that works, but from little what I know, it is similar to acid, with the added risk of dying from the venom itself. If this kid is so much about animal activism, why does he and his friends not care about those instances of animal abuse from the corrupt, rich people? Why does he not care about the inhumane dairy industry or the industrialized broiler chicken farm? Just needed some opinion on this, because I am kinda ticked off by this brat's behaviour.

    20
    3
    "Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearVE
    Now
    508 1.7K

    LalSalaamComrade

    velox_vulnus@ lemmy.ml