/r/c_language

Photograph via snooOG

Anything related to the C (NOT C++) programming language

/r/c_language

7,283 Subscribers

1

simple-txt , v0.3-Hello Linux!!

0 Comments
2024/11/07
16:54 UTC

1

i cannot compile my C coding in Visual Studio and other IDEs, how to FIX??

1 Comment
2024/10/22
10:11 UTC

3

Is it hard to learn C from the K&R book

I've always had an interest in languages like C,C++,RUST and recently started to learn C from the book by Kernighan and Ritche and I am finding it very hard to follow. The only other programming language I know is javascript, I am not a complete beginner to programming but definitely a beginner in low level programming. Despite having experience with basic programming concepts, It's taking me a lot of time to keep up with the examples and exercises in the book. Is the book really hard or am I just not meant for low level programming.

7 Comments
2024/08/07
09:24 UTC

0

Can you help me?

I wanted to print a identity matrix but couldn't do it (in C). Where did i go wrong? (english is not my first launguage i'm sorry for any mistakes)

https://preview.redd.it/m2b41z1h12hd1.png?width=632&format=png&auto=webp&s=1f6bf740585014441452aba2ddef8f3445b5ee12

2 Comments
2024/08/06
14:35 UTC

1

What should I #include if I want to use direct3d?

0 Comments
2024/08/01
22:38 UTC

1

An example of an SDL2 setup for MacOS

0 Comments
2024/07/08
17:20 UTC

6

OpenSSF Best Practices for produce application binaries with security mechanisms against potential attacks and/or misbehavior.

Hi all.

I found this Compiler Options Hardening Guide for C and C++ by OpenSSF Best Practices Working Group.
Some one is using the suggested compiling options? Any comment :-)?

0 Comments
2024/06/10
19:28 UTC

13

The basics of C

Guys, I'm new to the C language. And I would like to know where to start with it, if anyone has a "map" to tell me where to follow to have a good learning, I would be gratefulGuys, I'm new to the C language. And I would like to know where to start with it, if anyone has a "map" to tell me where to follow to have a good learning, I would be grateful
7 Comments
2024/06/01
00:23 UTC

1

Type hinting in C?

I mean, polymorphism in C is a pain. For obvious reasons, generalized C code will consist of structures containing void* pointers and functions returning such structures (or pointers to them, or exactly the same void* pointers).

Next, you look at the library documentation and learn how you should cast types for further work.

The situation could be saved by some Python-style type-hinting. None of changes and guarantees at runtime, but with hints in a smart enough IDE and warnings at compile time if you cast pointers in some unexpected way. So you always know without documentation and looking into source code where the pointer is pointing

For example, something like this:

typedef void* gpointer;

typedef struct _GPtrArray;

__attribute__(generic_struct, TDATA)
struct _GPtrArray
   {  
      gpointer *pdata; __attrubute__(cast_field, TDATA)
      guint    len;
   };

...

__attribute__(cast_return, *InstalledRef)
GPtrArray*
function_list_installed_refs(...args) 
   { 
      ... 
   }

__attribute__(cast_return, *RecentlyDeletedRef)
GPtrArray*
function_list_recently_deleted_refs(...args)
   { 
      ... 
   }

int 
calculate_something(
   GPtrArray *installed __attribute__(cast_arg, *InstalledRef)
) 
   { 
      ... 
   }

...

g_autoptr(GPtrArray) installed = function_list_installed_refs(...);
for (guint i = 0; i < apps->len; i++)
    {
      // warnings
      // 1.    RecentlyDeletedRef *app = g_ptr_array_index (apps, i);
      // 2.    ... (RecentlyDeletedRef*)g_ptr_array_index (apps, i) ...
      // 3.    void *app = g_ptr_array_index (apps, i);
      // 4.    int value = calculate_something(app);
               
      // okays 
      // 1.    InstalledRef *app = g_ptr_array_index (apps, i);
      // 2.    (InstalledRef*)g_ptr_array_index (apps, i)
      // 3.    int value = calculate_something(app);
    }

Are there any C compiler extensions that provide this capability? Or maybe there are complexities that make this approach stupid (impossible or impractical)?

It seems to me that it should be very convenient for developers and very useful for static analysis but I cannot find any info in the web.

3 Comments
2024/05/28
14:13 UTC

4

Should the main function return a value other than 0 by default when the only way the program will finish with an expected result is inside a condition that's inside a loop? or should i create a variable for this condition and return 0 outside the loop?

I know it works anyway, i just want to know if it's a bad practice to the standard conventions of the language. I didn't find an answer by searching it

4 Comments
2024/05/07
03:22 UTC

2 Comments
2024/04/27
16:09 UTC

0

calculating with double and int

In C , when calculating with double and int , the final data of the expression transform from double to int ?

8 Comments
2024/04/27
06:31 UTC

0

C language

After finishing the basics of C, I don't know what to do after? How to work with??

3 Comments
2024/04/19
17:08 UTC

1

Is this possible in strict?

struct number { int a, b; int c=a+b; }S;

S.a=6; S.b=7; //Then print S.c.

1 Comment
2024/04/01
08:13 UTC

1

#warnings showing up twice

The following warning from the following screen.h file shows up twice when compiling:

#ifndef _SCREEN_H
#define _SCREEN_H

#ifndef SCREEN_WIDTH
#define SCREEN_WIDTH 320
#warning "SCREEN_WIDTH not defined. Defaults to 320."
#endif

#endif //_SCREEN_H

The screen.h file is included in two other files. I thought using the method with defines only included this file once. What gives?

2 Comments
2024/03/27
19:43 UTC

Back To Top