The one and only thread for C programmers.
/C General/
Other urls found in this thread:
cprogramming.com
knking.com
twitter.com
Isn't /dpt/ pretty much all C as it is?
been looking at some """alternative""" minimal IDE's with OS X support and tried out Geany. Pretty good
Specifically because you've tried using a text editor + gcc (for example) and didn't like it; or have you not tried that? No hate either way but if you haven't tried I would recommend Vim + GCC.
is geany really a IDE?
i use it but compile and everything outside of it.
i know its a blurred line and all
starting self learning programming with C, wish be luck
making an interpreter using C/flex/bison
good lug
No. Are you blind? They all do some flavour of Java (C# F#), a functional language or C++/D.
Hardly anyone does actual C.
vim
Is there any point using gdb on windows, can't find much documentation for windows
For example
print doesn't work on gdb on windows
Should I just skip it
look up cprogramming.com's gdb tutorial
if you don't like it look up beej's gdb tutorial
just started learning C. halfway though OPpicrelated. What gotcha sort of things did you guys learn outside of that book?
i'm going through beej's guide to networking atm
what's the point, some of the things on there won't work for me. I'm assuming these tutorials are mainly aimed at unix-systems not windows
>what's the point
hey man, if you wanna have a bunch of grumpy coders yell at you keep posting like this.
your motivation has to be internal. if you ask specific questions we can help but i can't counsel you about your psychology.
Are there any decent GUI builders for C
as far as i know if you want cross platform support, use qt creator
> Qt
> C
0/10
gtk+
m8, there's nothing wrong with my motivation
I am finally at the end of this book and it's telling me about gdb debugger
I am asking if it's pointless on windows as it's not working well for me
and you're linking me useless tutorials that are doing the same thing
For cross platform support Qt is better but GTK+ is our sentimental favourite for standing up to Qt during its closed-source days.
>Debugging is a critical skill, but most people aren't born with a mastery of it. Debugging is hard for a few reasons; first, it's frustrating. You just wrote a bunch of code, and it doesn't work even though you're pretty sure it should. Damn! Second, it can be tedious; debugging often requires a lot of effort to narrow in on the problem, and until you have some practice, it can be hard to efficiently narrow it down. One type of problem, segmentation faults, are a particularly good example of this--many programmers try to narrow in on the problem by adding in print statements to show how far the program gets before crashing, even though the debugger can tell them exactly where the problem occurred. Which actually leads to the last problem--debuggers are yet another confused, difficult to set up tool, just like the compiler. If all you want is your program to work, the last thing you want to do is go set up ANOTHER tool just to find out why.
Windows? Why bother with C when there's C#?
dunno what else anyone can do for you m8. i linked you to two great gdb tutorials which would walk you through exactly what functionality you would need.
stop looking for meaning where there is no meaning
How do I write C programs with zero dependencies?
I want to use it as a cheap assembler, not necessarily portable. I dont even want the gigantic C runtimes linked into my program.
>print doesn't work on windows
btw do you mean the list command?
just set up a fedora 25 coding workstation
Guess I'm skipping it
thanks for nothing
you tell your compiler not to link in crt0 or equivalent (consult your compiler tool chain's documentation for this). Then it's very dependent on your environment.
There's a debugging course on udacity. It's good.
>C
Portable
Scalable
Perfect to learn how to program and design software
>C#
Lol
>scalable
Lol. There's nothing inheremt in C that makes it scalable. Scalability is about using resources as they become available. It's about the structure of your system.
Are there tools to automatically generate C wrapper to C++ header?
Which utility library should be used: tbox, glib, qlibc, apr or something else?
They all suck. Specially [e]glib.
Yeah but don't really want to reimplement allocators, basic data structures and the cross platform directory walking when there's already more libraries that do it than there atoms in the universe.
Any good course/book for learning C?
Learn C the hard way is good if you're not a programming beginner. Gives you a decent base to really get into C quickly.
I never understood function pointers. Can you give me a minimal working example?
#include
#include
#include
int cmp(const void *_a, const void *_b)
{
const int *a = _a, *b = _b;
if (*a < *b)
return -1;
if (*a > *b)
return 1;
return 0;
}
int main()
{
srand(time(NULL));
int arr[10];
for (int i = 0; i < 10; ++i)
arr[i] = rand() % 20;
puts("Before:");
printf("%d", arr[0]);
for (int i = 1; i < 10; ++i)
printf(", %d", arr[i]);
putchar('\n');
qsort(arr, 10, sizeof arr[0], cmp);
puts("After:");
printf("%d", arr[0]);
for (int i = 1; i < 10; ++i)
printf(", %d", arr[i]);
putchar('\n');
}
Thanks, I got it now. But one more question (I'm kind of a newbie in C): What is this idiom?
const void *_a
I know that int *a means: "a is an address at which an int value is stored", or "a is a pointer to an int value", or "dereferencing a results in an int".
Similarly,
void *_a
means "dereferencing _a results in a void". But that can't be right, so what does this really mean? I can guess that it somehow takes the int values from the array in order to compare them for sorting, but how does that really work?
Thanks so much!
Also is the leading underscore just a naming convention? Where do you get all of this knowledge from? Can you recommend a book that covers these more advanced features/tricks/conventions?
The void pointer can't be dereferenced. There's no type, no size, no alignment. You must cast it.
#include
int main(void)
{
int i;
for(i=1; i
A void pointer is a pointer to an unspecified type. You cannot dereference a void pointer, because the compiler has no idea what it actually points to.
It order to use it, you need to convert it to another pointer type, as I did when it assigned it to 'a' and 'b'.
The const just means that I can't modify it.
void pointers are used when you want to write functions that can deal with potentially any type of data.
Another good example from the standard library would be memcpy, or the return value of malloc.
The qsort function accepts a function pointer that uses void pointers, so the programmer can use qsort for any type of array.
Say I wanted to sort an array of floats, I would do
int cmp(const void *_a, const void *_b)
{
const float *a = _a, *b = _b;
// ...
}
>I can guess that it somehow takes the int values from the array in order to compare them for sorting
Right.
>but how does that really work?
It uses the size arguments given to the function.
So internally, say qsort was comparing the element at index 2 and index 5. It would be doing something like
// Note the conversion to char *, because we cannot do pointer arithmetic on a void pointer
const char *ptr = base;
compar(base + size * 2, base + size * 5);
>Also is the leading underscore just a naming convention?
Nah. I was just being lazy and couldn't be bothered thinking of a good name for the arguments.
Sometimes a single leading underscore can mean "unimportant" or "private implementation details", but there is no real convention for this.
>compar(base + size * 2, base + size * 5);
Wait, I screwed that up:
compar(ptr + size * 2, ptr + size * 5);
Is C a meme?
Is it actually useful nowadays?
Correct me if I'm wrong, but isn't the book in OP wildly outdated by today's standards? Surely you aren't doing everything in ANSI C?
You can do pretty much anything in C but unless you are writing something that specifically requires C (some low level stuff) or libraries some other language is probably better than C.
C is poor choice for application development because all the cool libraries are in C++ but if what C's ecosystem currently has is enough then C decent language.
Nice. Thank you so much again for the explanation!
What function reads a character from the keyboard without having to press Enter?
I want to make a simple vi clone.
Beej is a god
>anything by zed shaw
user what the fuck is wrong with you?
Dear library makers, please stop making macros that are supposed to be used like functions by the end user.
I've heard that C programming doesn't work on Windows. I've got a virtual machine set up with Linux so I can learn it, and now everyone seems to be saying that I could absolutely do C programming in Windows if I wanted to. So what was I thinking of? I swear C was too low-level, and got blocked by some Windows security feature or something. Please tell me I'm not imagining this.
worked fine for me on win7 some years ago.
these days... who the fuck knows
C is the only language that isn't a meme.
best C book other than The C Programming Language
Whats a good resource to learn every feature and language piece of C? I already read K&R and C Programming Guide
Macros should be indistinguishable from functions.
>learning C
>not installing BSD or Linux on some VM at the very least
come the fuck on user
can't you just mix both?
What did you mean by this?
#define set_as_sum(x, y) (x) = (x) + (y)
Might terrible example but the x get's evaluated 2 times which should not happen.
Also macros should be able to generate other macros for example.
#define includes(incs ...) \
#LOOP(incs)(#include )
Ugly and hypothetical implemation that is impossible in C but that could be in the language to allow macros that define macros.
It would exapand into
includes(stdio, math);
/* expands into */
#include
#include
isn't that lisp's thing?
There's really no reason to it to be only lisp thing.
Using lisp reader while executing macros is lisp thing but it does not mean C should improve from the shitty text replacement which could be achieved with simple sed script.
Too bad C's standard commitee us full of faggots that kind can't do anything good to a language.
The C macro system is simple and primitive on purpose. It's that way so that it's easy to implement, and doesn't turn into some Turing-complete clusterfuck like C++ templates.
Also, it is FAR too late to make some sort of massive, breaking change like that.
The reason you shouldn't do it is because it makes interfacing obnoxious, you can use them all you want in the library itself, but wrap them in functions of the macro needs to be used by the user.
I never use static. Is this bad?
>Turing-complete clusterfuck like C++ templates
Valid fear but I'm not convinced that the other extreme is good solution.
>bu.. bu.. but IT'S TOO LATE
>let's standardize all this optional shit that no will ever (c11)
Too bad C has no good way to expand itself because the only reserved way is with stuff that begins with _ and capital letter.
no
There isn't one in the standard library, because that's an implementation detail. The standard library makes no assumption on HOW input is recieved, the OS can decide to store keystrokes in a linebuffer and send them when you press enter, or can send them as they're typed. Most C library implementation use the linebuffer method, so to detect single keypresses requires an OS specific solution.
Not a problem if the macros are well designed.
lel, this.
look up ncurses
Is it worth learning C? I've tried my hand at python but got bored pretty quickly. Should I try C instead or just stop trying to program altogether?
I just downloaded Beej's guide and wish to know if there's any difference between windows and linux for a platform to learn C. Specifically , are Linux/Unix tools and compilers better than windows.
For some reason, C just seems to attract me.
Am I normal?
>Specifically , are Linux/Unix tools and compilers better than windows.
hell yes
>Specifically , are Linux/Unix tools and compilers better than windows.
leagues better
Thanks Gents. You guys are fast tonight
This, I die a bit inside when I have to make a thin binding in c because the library creator couldn't be bothered.
we're not here to offer psychological support. we're here to answer questions about programming in C. we are too autistic to help you with your emotional or motivational issues
also i'm probably gonna trigger an autist but check out openbsd, it has nice man pages for standard library stuff
beej
Make America Great Again
Make America Great Again
Make
Make America Great Again
America
Make
GreatMake America Great Again
Make America Great Again
Make
America
Make America Great Again
Make
Make America Great Again
GreatMake America Great Again
MakeAmerica
Make America Great Again
Make America Great Again
Make
Make America Great Again
America
MakeGreat
Make America Great Again
Make America Great Again
Make
America
Make America Great Again
Make
GreatMake America Great Again
Make America Great Again
MakeAmerica
Make America Great Again
Make America Great Again
Make
Make America Great Again
AmericaGreat
Make
Make America Great Again
Make America Great Again
Make
America
Make America Great Again
MakeGreat
Make America Great Again
Make America Great Again
MakeAmerica
Make America Great Again
Make America Great Again
Make
GreatMake America Great Again
America
Make
Make America Great Again
Make America Great Again
Make
America
GreatMake America Great Again
Make
Make America Great Again
Make America Great Again
MakeAmerica
Make America Great Again
Make America Great Again
MakeGreat
Make America Great Again
America
Make
Make America Great Again
Make America Great Again
Make
America
Won't using openbsd turn me into an unapproachable guru?
bump
Openbsd is great
I use static variables when making generators/coroutines. My limited experience prevents me from thinking of any other purpose. I don't use static in any other way too.
I'm here to offer psychological support.
Quit as soon as possible and forget everything by going on a drug bender. Shave up about $10k and hit up the shadiest, most degenerate weed you can and buy all the fun. It will be so much better than C programming.
what's a good way to time a C program, or set up some sort of bench testing type shit to run it a bunch of times and all that?
>gdb on windows
just use vs on windows
stopwatch, or some sort of profiling tool, like Instruments on mac
>hardly anyone does actual C
>create a C thread
jesus christ
makes sense to me
//print from one to 10 then back down to zero
#include
#include
void print_plus_one(void) {
static int a = 0;
printf("%d\n", a);
static bool reachedTen = false;
if(a == 10){
reachedTen = true;
};
if (reachedTen == false){
a++;
};
if(reachedTen == true){
a--;
};
}
int main(void) {
for(int i=0; i
Why should I learn C? Programming is for wasgeslaves
cuck
>why should I learn English? Reading is for wageslaves
desu I don't understand why C programmers hate on C++ so much
I grew up with both and I think they are both the best
>C is poor choice for application development because all the cool libraries are in C++
> C++
> Libraries
HAHAHAHAHAHAHAHAHA