/r/c_language
Anything related to the C (NOT C++) programming language
/r/c_language
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.
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)
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 :-)?
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
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.
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
In C , when calculating with double and int , the final data of the expression transform from double to int ?
After finishing the basics of C, I don't know what to do after? How to work with??
struct number { int a, b; int c=a+b; }S;
S.a=6; S.b=7; //Then print S.c.
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?