[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/C General/

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 135
Thread images: 5

The one and only thread for C programmers.
>>
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
>>
>>58571619

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.
>>
>>58571619
is geany really a IDE?

i use it but compile and everything outside of it.
>>
>>58571706
i know its a blurred line and all
>>
starting self learning programming with C, wish be luck
>>
making an interpreter using C/flex/bison
>>
>>58571762
good lug
>>
>>58571464
No. Are you blind? They all do some flavour of Java (C# F#), a functional language or C++/D.

Hardly anyone does actual C.
>>
>>58571619
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
>>
>>58571852
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?
>>
>>58571884
i'm going through beej's guide to networking atm
>>
>>58571869
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
>>
>>58571913
>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.

http://www.cprogramming.com/debugging/debugging_strategy.html
>>
Are there any decent GUI builders for C
>>
>>58571943
as far as i know if you want cross platform support, use qt creator
>>
>>58571960

> Qt
> C

0/10
>>
>>58571943
gtk+
>>
File: C.jpg (30KB, 376x499px) Image search: [Google]
C.jpg
30KB, 376x499px
>>58571923
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
>>
>>58571943
For cross platform support Qt is better but GTK+ is our sentimental favourite for standing up to Qt during its closed-source days.
>>
>>58572018
>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.
>>
>>58572018
Windows? Why bother with C when there's C#?
>>
>>58572018
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.
>>
>>58572069
>print doesn't work on windows
btw do you mean the list command?

just set up a fedora 25 coding workstation
>>
>>58572069
>>58572068
>>58572056
Guess I'm skipping it
thanks for nothing
>>
>>58572075
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.
>>
>>58572056
There's a debugging course on udacity. It's good.
>>
>>58572068
>C
Portable
Scalable
Perfect to learn how to program and design software
>C#
Lol
>>
>>58572130
>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?
>>
>>58572319
They all suck. Specially [e]glib.
>>
>>58572333
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?
>>
>>58572395
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?
>>
>>58572540
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

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');
}
>>
>>58572653
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!
>>
>>58572787
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?
>>
>>58572787
The void pointer can't be dereferenced. There's no type, no size, no alignment. You must cast it.
>>
#include <stdio.h>

int main(void)
{
int i;
for(i=1; i<=100; ++i)
{
if (i % 3 == 0)
printf("Make");
if (i % 5 == 0)
printf("America");
if (i % 7 == 0)
printf("Great");
if ((i % 3 != 0) && (i % 5 != 0))
printf("Make America Great Again");
printf("\n");
}

return 0;
}
>>
>>58572787
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);


>>58572795
>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.
>>
>>58572895
>compar(base + size * 2, base + size * 5);
Wait, I screwed that up:
compar(ptr + size * 2, ptr + size * 5);
>>
>>58571459
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?
>>
>>58574342
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.
>>
>>58572895
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.
>>
>>58571888
Beej is a god
>>
>>58572449
>anything by zed shaw
anon 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.
>>
>>58576573
worked fine for me on win7 some years ago.

these days... who the fuck knows
>>
>>58574342
C is the only language that isn't a meme.
>>
>>58572395
http://knking.com/books/c/

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
>>
>>58575648
Macros should be indistinguishable from functions.
>>
>>58571913
>learning C
>not installing BSD or Linux on some VM at the very least
come the fuck on anon
>>
>>58571969
can't you just mix both?
>>
>>58578788
What did you mean by this?
>>
>>58579134
#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 <#CURRENT.h>)

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 <stdio.h>
#include <math.h>
>>
>>58575648
>>58578788
isn't that lisp's thing?
>>
>>58580332
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.
>>
>>58580396
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.
>>
>>58578788
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?
>>
>>58580487
>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.
>>
>>58580559
no
>>
>>58574882
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.

>>58575648
Not a problem if the macros are well designed.
>>
>>58578078
lel, this.
>>
>>58574882
look up ncurses
>>
>>58571459
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?
>>
>>58571459
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?
>>
>>58581986
>Specifically , are Linux/Unix tools and compilers better than windows.
hell yes
>>
>>58581986
>Specifically , are Linux/Unix tools and compilers better than windows.

leagues better
>>
>>58581997
>>58582035
Thanks Gents. You guys are fast tonight
>>
>>58580528
This, I die a bit inside when I have to make a thin binding in c because the library creator couldn't be bothered.
>>
>>58581975
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
>>
>>58581986
>>58581997
also i'm probably gonna trigger an autist but check out openbsd, it has nice man pages for standard library stuff
>>
>>58572395
beej
>>
>>58572871

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
>>
>>58582164
Won't using openbsd turn me into an unapproachable guru?
>>
>>58582322
Openbsd is great
>>
>>58580559
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.

>>58582143
I'm here to offer psychological support.

>>58581975
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?
>>
>>58571852
>gdb on windows
just use vs on windows
>>
>>58585275
stopwatch, or some sort of profiling tool, like Instruments on mac
>>
>>58571794
>hardly anyone does actual C
>create a C thread
jesus christ
>>
>>58585937
makes sense to me
>>
//print from one to 10 then back down to zero

#include<stdio.h>
#include<stdbool.h>

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<21; i++){
print_plus_one();
}

return 0;
}
>>
>>58571459
Why should I learn C? Programming is for wasgeslaves
>>
>>58586847
cuck
>>
>>58586847
>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
>>
>>58574454

>C is poor choice for application development because all the cool libraries are in C++

> C++
> Libraries

HAHAHAHAHAHAHAHAHA
>>
>>58586935
>
>>
>>58572449
Beginning linux programming is good

I mean look at the mfs on this cover.jpg
>>
Hey Guyz N00b Here

I have serious question, what do you use programming for? Like do you have any practical applications or your just writing code to experiment with dumb programs.

Like I don't see much use of programming in daily life...

Like give me straight forward answer like .... I use programming to make programs who help me sort millions of emails or something like that...
>>
>>58574342
useful for embedded stuff, microcontroller programming with or without an OS
>>
>>58587170
I write programs to make money
>>
>>58587317
How excatlly do you make money programming?
>>
File: tYHNN5T1.jpg (190KB, 960x895px) Image search: [Google]
tYHNN5T1.jpg
190KB, 960x895px
>>58586881
>he fell for the learning meme
>>
>>58586847
Also
>implying learning C is as useful as learning English for 99.999999% of the populace
>>
>>58587328
more precicely, I make money being a software engineer. This isn't just programming this is design, requriements analysis, etc...

you get a bachelors of science in computer science or computer engineering from an accredited school, and you get hired by a company

do i need to spell it out more for you?
>>
>>58571826
Have fun fucking around with visual block mode and regexes while I'm sitting here doing multi-line edits with Sublime Text in under five seconds
>>
>>58587555
Yes, usually people give vague description of jobs to sound interesting and complex but in reality is just something like reinstalling microsoft word and other crappy programs for other people working in cubicles.

>requirements analysis
stop trying to sound sophisticated, its that just something like checking how much MB you have left on hard disk?
>>
>>58587570
Sublime is for plebs vi(m)aster race
>>
>>58587592
>that just something like checking checking how much MB you have left on hard disk?
yes

but you have no idea how often these software """""engineers""""" manage to fuck that up
>>
File: 1484932155036.jpg (32KB, 480x360px) Image search: [Google]
1484932155036.jpg
32KB, 480x360px
>>58587683
>not having function / keyword completion and brackets completion in your editor
>having to manually trigger autocompletion
>>58587570
my nigga
>>
Are C, C#, C++ designed for different purposed? What are their best applications? Ive jumped into C#, but only because Unity uses it though.
>>
>>58582322
it's great for learning C imo
>>
>>58587592
you have no idea, ok I will tell you

what i do is write the software for body modules in vehicles. I've written software for all wheel drive relays, a switch that communicates over LIN, a fuel tank sensor and drive line relay that communicates over CAN

I've done these in C for various microcontrollers as small as (then freescale now NXP) S08, S16, Renesas v850

companies still need custom solutions, even when you think something off the shelf would work

requirements analysis is literally going through the crap document the customer drafts that says "I want A B and C" and making those into testable requirements

I understand your frustration with people before who may not have described what it is they really do and what the buzzwords really mean, so I hope this helps
>>
>>58587735
>software """""engineers"""""
I get it, there is no real standard for what constitutes a software "engineer" in the US. However in Canada and Europe there are actual certifications required before one can call themselves that
>>
What's a good language to get me learning C later on?
>>
>>58571794
>webshit
ftfy
>>
>>58572449
>Learn C the hard way is shit
ftfy
>>
>>58578788
wrong
>>
>>58588952
I'd recommend starting out with punch cards
>>
>>58571852

IMO it's kind of silly to do C development on Windows. At least run Linux in a VM, you get GDB and Valgrind, too.
>>
>>58589143
>IMO it's kind of silly to do C development on Windows.
its not if you're doing games
>>
>>58589469
Nobody uses C on windows it's all C++ or C#.
>>
>>58589057
I would if I could, but I lack a teletypewriter
>>
>>58587570
i am with you
>>
>>58589482
some do, but you're right it's mostly C++ or C#
>>
>>58576573
You can't access things out of the ram state without other specific programs. Just the way the patent rolled after everyone took to picking at the data states.

That means that in Linux you can edit the sound buffer, video buffer, frame buffer and all that using just the standard library but since the developers had to make the program for windows anyway, they ported it to linux.

On windows you need a ton of extra help. Windows couldn't continue to flourish as it is if people become aware of how much they could do by just learning that one little language.

Maybe it's not the Microsoft endgame but it's certainly part of it.
>>
>>58571852
Windows isn't friendly to C and you're better off using Visual Studio 2015 and installing its C++ repository. Ignore all of the C++ nonsense but not the MS portion that you need to use for it to work under Windows. Now you're set to program C under the Windows platform.

But honestly, if you really want to learn C, you should install a Linux OS since C was made for Unix and Linux has an association with Unix to begin with. Plus you get to use all of the sweet, sweet tools that was made for the language, such as valgrinder and gdb.
>>
>>58589482
This. C is too unix idiosyncratic. C++ and C# are better fits for Windows. I'd go for C#, hanestry
>>
>>58588952
C is a perfectly good first language
If you want to do reverse engineering or binary hacking I'd suggest assembly first.
>>
>>58587170
Im just starting college and working more with the electronics more than with the programming (using c on a bit level) but im currently modifying a lamp to make it blink and sound like the TARDIS as a gift to my gf, because she loves Dr who and im really digging it too RN.

I also took a mic out of a pair of old headphones and know i clap to turn the bathroom lights on and off.
So, yeah, you can make pretty fun stuff.
>>
>>58571459
So I work in very-high-level-languages like Java and C# which is cool but it is basically like playing with LEGO. Sure it is programming but everything is done for you and you just have to connect the pieces together. This is great for getting stuff done for work but it isn't really lots of fun.

I have wanted to learn C because it just looks fun. Annoying but fun. Where is a good place for someone like myself to start? I started reading a copy of A Modern Approach but it spent so much time going over the very basics of loops, etc. that I didn't read any further. Is there a good book for not a total beginner but for someone who hasn't had to work with C pointers, manual memory management, no GUI toolkit built in, etc? Maybe something that covers threading, networking, GTK or Win32 for GUI, etc. ? Or if no books are there some good sites or such? Would be cool to have a resource which has, for example some Java code and then C code that does the same thing and explanations on how and why things are different.
>>
>>58571852
gdb works on windows such a few exceptions (like tui mode doesnt work). or you can use windbg, cdb or the visual studio debugger if you wish. they all work great on windows.
Thread posts: 135
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.