1
5
submitted 4 days ago by t0mri@lemmy.ml to c/c_lang@programming.dev

cross-posted from: https://lemmy.ml/post/17545833

im new to system programming, idk if thats the issuse. but according gcc, it can not find dbus/dbus-arch-deps.h and thats all i know. any idea about this issue?

 program
[I] tomri@artix ~ [1]> cat main.c
#include <dbus-1.0/dbus/dbus.h>

int main(void) { return 0; }
# error
[I] tomri@artix ~> gcc main.c
In file included from main.c:1:
/usr/include/dbus-1.0/dbus/dbus.h:29:10: fatal error: dbus/dbus-arch-deps.h: No such file or directory
   29 | #include <dbus/dbus-arch-deps.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
[I] tomri@artix ~> ls -la /usr/include/dbus-1.0/dbus/
total 216
drwxr-xr-x 2 root root  4096 Jul  2 20:26 ./
drwxr-xr-x 3 root root  4096 Jun 15 21:36 ../
-rw-r--r-- 1 root root  2809 Jan 14 06:17 dbus-address.h
-rw-r--r-- 1 root root  3470 Jan 14 06:17 dbus-bus.h
-rw-r--r-- 1 root root 27018 Jan 14 06:17 dbus-connection.h
-rw-r--r-- 1 root root  2909 Jan 14 06:17 dbus-errors.h
-rw-r--r-- 1 root root 22076 Jun  8  2023 dbus-glib-bindings.h
-rw-r--r-- 1 root root  2575 Jun  8  2023 dbus-glib-lowlevel.h
-rw-r--r-- 1 root root 14766 Jun  8  2023 dbus-glib.h
-rw-r--r-- 1 root root  8969 Jun  8  2023 dbus-gtype-specialized.h
-rw-r--r-- 1 root root  1464 Jun  8  2023 dbus-gvalue-parse-variant.h
-rw-r--r-- 1 root root  7246 Jan 14 06:17 dbus-macros.h
-rw-r--r-- 1 root root  1961 Jan 14 06:17 dbus-memory.h
-rw-r--r-- 1 root root 15259 Jan 14 06:17 dbus-message.h
-rw-r--r-- 1 root root  1810 Jan 14 06:17 dbus-misc.h
-rw-r--r-- 1 root root  3809 Jan 14 06:17 dbus-pending-call.h
-rw-r--r-- 1 root root 23956 Jan 14 06:17 dbus-protocol.h
-rw-r--r-- 1 root root  5412 Jan 14 06:17 dbus-server.h
-rw-r--r-- 1 root root  5392 Jan 14 06:17 dbus-shared.h
-rw-r--r-- 1 root root  3047 Jan 14 06:17 dbus-signature.h
-rw-r--r-- 1 root root  2359 Jan 14 06:17 dbus-syntax.h
-rw-r--r-- 1 root root  8505 Jan 14 06:17 dbus-threads.h
-rw-r--r-- 1 root root  4143 Jan 14 06:17 dbus-types.h
-rw-r--r-- 1 root root  3961 Jan 14 06:17 dbus.h
[I] tomri@artix ~> 
# my system
[I] tomri@artix ~> uname --all
Linux artix 6.9.7-artix1-1 #1 SMP PREEMPT_DYNAMIC Fri, 28 Jun 2024 18:11:28 +0000 x86_64 GNU/Linux
2
6
3
8
4
13
5
6

TCC fails with GNU's regex.h:

echo '
                                              #include <regex.h>

                                              int main() { return 0; }' | tcc - -run
In file included from -:2:
/usr/include/regex.h:682: error: '__nmatch' undeclared

Would building it from source fix the issue? I know from my experience that Pop_OS! apt repositories are not very up-to-date with smaller apps. For example, NekoVM is from 2017, the latest one is from 22 I believe.

6
20
7
22
One year of C (2018) (floooh.github.io)
8
5
submitted 3 months ago* (last edited 3 months ago) by promitheas@iusearchlinux.fyi to c/c_lang@programming.dev

Hello everyone :)

I recently wrote a small blackjack game where the challenge I set myself (and the learning goal) was to use pointers to do stuff. So for example instead of having all my functions written in such a way as to avoid using pointers I would use them wherever possible.

It works in its current form and seems to do so quite well, but I would like to learn even more from this project. So here I am asking for your experience. Please give me any suggestions, advice, ways to make it more efficient in terms of memory used, ways to make it more efficient in terms of speed (I know memory and speed might not be so important for a small project like this but my goal is to practice and learn the underlying concepts), criticisms, best practices, or anything you that comes to mind when you look at the code.

As an example of what I mean, I would like to make it so that the arrays which hold the player and dealer hands are not of fixed size on declaration, but grow and shrink dynamically as cards are added and removed from them (practice memory allocation/deallocation).

I hope I provided enough info about what I am looking for in a clear manner, but if not please do ask for clarification/additional info.

Thanks in advance!

9
9
10
28
submitted 3 months ago by ylai@lemmy.ml to c/c_lang@programming.dev
11
15
12
14
C can be memory-safe (2023) (blog.erratasec.com)
13
23

Almost 50 years ago, the C language defined modern computer programming. This book shows you why C is still as powerful and popular as ever, with an inside look at the new C23 standard.

For programs that need to be small, fast, and unfailingly reliable, C is still the gold standard. Whether you’re writing embedded code, low-level system routines, or high-performance applications, C is up to the challenge. This unique book by Jens Gustedt, a member of the ISO C standards committee, gets you up to speed with C23.

In Modern C, Third Edition you’ll:

  • Learn C basics, core features, and advanced concepts
  • Leverage major C23 improvements for security, reliability, and performance
  • Write portable code that runs anywhere
  • Build multi-threaded applications with atomics and synchronization
  • Create robust and resilient software with error handling
  • Use type-generic programming for reusable code

C powers more software than any other language — from embedded devices to distributed systems. In Modern C, Third Edition you’ll learn to harness C’s full potential using the latest tools and techniques. After a quick review of the fundamentals perfect for beginners or coders who haven’t used C in a while, this book guides you to mastery of C23, the latest ISO standard.

14
-4
submitted 4 months ago* (last edited 4 months ago) by modev@programming.dev to c/c_lang@programming.dev

Maybe you have to hear about this.

What do you think?

I think:

C will never die

For infrastructure technology, C will be hard to displace. © Dennis Ritchie

15
17

Developers struggle with C pointers because they do not feel confident. I found a very good book about it: Understanding and Using C Pointers by Richard Reese.

"Why You Should Become Proficient with Pointers

Pointers have several uses, including:

  • Creating fast and efficient code
  • Providing a convenient means for addressing many types of problems
  • Supporting dynamic memory allocation
  • Making expressions compact and succinct
  • Providing the ability to pass data structures by pointer without incurring a large overhead
  • Protecting data passed as a parameter to a function

Faster and more efficient code can be written because pointers are closer to the hardware.

That is, the compiler can more easily translate the operation into machine code. There is not as much overhead associated with pointers as might be present with other operators.

Many data structures are more easily implemented using pointers. For example, a linked list could be supported using either arrays or pointers.

However, pointers are easier to use and map directly to a next or previous link. An array implementation requires array indexes that are not as intuitive or as flexible as pointers."

"A solid understanding of pointers and the ability to effectively use them separates a novice C programmer from a more experienced one. Pointers pervade the language and provide much of its flexibility. They provide important support for dynamic memory allocation, are closely tied to array notation, and, when used to point to functions, add another dimension to flow control in a program.

Pointers have long been a stumbling block in learning C. The basic concept of a pointer is simple: it is a variable that stores the address of a memory location. The concept, however, quickly becomes complicated when we start applying pointer operators and try to discern their often cryptic notations. But this does not have to be the case. If we start simple and establish a firm foundation, then the advanced uses of pointers are not hard to follow and apply.

The key to comprehending pointers is understanding how memory is managed in a C program. After all, pointers contain addresses in memory. If we don’t understand how memory is organized and managed, it is difficult to understand how pointers work. To address this concern, the organization of memory is illustrated whenever it is useful to explain a pointer concept. Once you have a firm grasp of memory and the ways it can be organized, understanding pointers becomes a lot easier."


Good explanation about "Differences Between Arrays and Pointers"

There are several differences between the use of arrays and the use of pointers to arrays. In this section, we will use the vector array and pv pointer as defined below:

int vector[5] = {1, 2, 3, 4, 5};
int *pv = vector;

The code generated by vector[i] is different from the code generated by vector+i. The notation vector[i] generates machine code that starts at location vector, moves i positions from this location, and uses its content. The notation vector+i generates machine code that starts at location vector, adds i to the address, and then uses the contents at that address. While the result is the same, the generated machine code is different. This difference is rarely of significance to most programmers. There is a difference when the sizeof operator is applied to an array and to a pointer to the same array. Applying the sizeof operator to vector will return 20, the number of bytes allocated to the array. Applying the sizeof operator against pv will return 4, the pointer’s size. The pointer pv is an lvalue. An lvalue denotes the term used on the lefthand side of an assignment operator. An lvalue must be capable of being modified. An array name such as vector is not an lvalue and cannot be modified. The address assigned to an array cannot be changed . A pointer can be assigned a new value and reference a different section of memory. Consider the following:

pv = pv + 1;
vector = vector + 1; // Syntax error

We cannot modify vector, only its contents. However, the expression vector+1 is fine, as demonstrated below:

pv = vector + 1;
16
18
17
5

Keep in mind that it is still buggy, i need to take a break from it and finish it up later. ASDL is a domain-specific language used to make Abstract Syntax Trees.

Thank.

18
3

AllocPP.pl is a script I authored that creates a dynamic heap (as in datatype heap, not the heap segment of the process) in your program, and these heaps are allocatable, and reallocatable, and deallocatable. It does so by preprocessing your program. It's in no way a substitution for memory management and garbage collection, but you can use it for one-off programs and tests. It has two directives, '#alloc' and '#hashfunc'. The latter is not important, just name your hash function anything. But the former is important. There can be as many heaps in your programs as possible.

There's an example, and full explanation in the Gist.

Thanks.

19
8

Hey. I have been posting this everywhere but few people seem to get what it is. Figured this will be the best place. Thanks.

20
24
Ode to C (programming.dev)

Personally, I have nothing against the emergence of new programming languages. This is cool:

  • the industry does not stand still
  • competition allows existing languages to develop and borrow features from new ones
  • developers have the opportunity to learn new things while avoiding burnout
  • there is a choice for beginners
  • there is a choice for specific tasks

But why do most people dislike the C language so much? But it remains the fastest among high-level languages. Who benefits from C being suppressed and attempts being made to replace him? I think there is only one answer - companies. Not developers. Developers are already reproducing the opinion imposed on them by the market. Under the influence of hype and the opinions of others, they form the idea that C is a useless language. And most importantly, oh my god, he's unsafe. Memory usage. But you as a programmer are (and must be) responsible for the code you write, not a language. And the one way not to do bugs - not doing them.

Personally, I also like the Nim language. Its performance is comparable to C, but its syntax and elegance are more modern.

And in general, I’m not against new languages, it’s a matter of taste. But when you learn a language, write in it for a while, and then realize that you are burning out 10 times faster than before, you realize the cost of memory safety.

This is that cost:

21
18
22
5
23
10
submitted 5 months ago by ylai@lemmy.ml to c/c_lang@programming.dev
24
2

So I'm making this program in SDL to just render a single window and it's not working IDK why. It compiles well no errors or anything and then when I try to run it nothing happens at all. No text appears nor a window. I tried to run my own code but it didn't work so I went to try and run the code off the website and that didn't work either.

CODE:

/This source code copyrighted by Lazy Foo' Productions 2004-2024 and may not be redistributed without written permission./

//Using SDL and standard IO #include <SDL.h> #include <stdio.h> #include <stdbool.h>

//Screen dimension constants const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480;

int main( int argc, char* args[] ) { //The window we'll be rendering to SDL_Window* window = NULL;

//The surface contained by the window
SDL_Surface* screenSurface = NULL;

//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
	printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
}
else
{
	//Create window
	window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
	if( window == NULL )
	{
		printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
	}
	else
	{
		//Get window surface
		screenSurface = SDL_GetWindowSurface( window );

		//Fill the surface white
		SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );
		
		//Update the surface
		SDL_UpdateWindowSurface( window );
        
        //Hack to get window to stay up
        SDL_Event e; bool quit = false; while( quit == false ){ while( SDL_PollEvent( &e ) ){ if( e.type == SDL_QUIT ) quit = true; } }
	}
}

//Destroy window
SDL_DestroyWindow( window );

//Quit SDL subsystems
SDL_Quit();

return 0;

}

25
5
view more: next ›

C Programming Language

931 readers
6 users here now

Welcome to the C community!

C is quirky, flawed, and an enormous success.
... When I read commentary about suggestions for where C should go, I often think back and give thanks that it wasn't developed under the advice of a worldwide crowd.
... The only way to learn a new programming language is by writing programs in it.

© Dennis Ritchie

🌐 https://en.cppreference.com/w/c

founded 1 year ago
MODERATORS