VOGONS


Reply 20 of 42, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie

Yeah, if you are not familiar with using C to write simple little things first, text display, file io, memory allocation etc, then I think jumping straight to VGA graphics display is likely a step too far.

My collection database and technical wiki:
https://www.target-earth.net

Reply 21 of 42, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie

lim, the answers to your questions are mostly, a "no". I have familiarity with keywords of the C programming language. Every book I come across that says to the effect of "Learn C" has done just that, teaching the essentials. I am ready however to move to the next level and learn the topics about pointer arithmetic, arrays, and how memory is used.

I have been thinking often today about switching to modern day C programming as a means of learning pointer arithmetic, arrays, memory, heap, stack, and other matters I need to learn.

So I am looking at two books about the basics of C that should be rigorous enough to cover the important aspects relevant to using C for programming. But after I meet these discussed prerequisites, I want to read a book about Allegro 5...it is a modern game development library written in C. I plan to use linux as the operating system
for my tool chain which I am not sure if I should use clang or gcc, but it will be the one that has "books" available.

Tell me what you think of the following titles:

Beej's Guide to C Programming by Brian "Beej Jorgensen" Hall 2023
Effective C by Robert C. Seacord 2020

Allegro 5 a search for books on Allegro 5 turn up many books

I'm thinking instead of the absolute basics of C I am ready to learn the points you made about C programming like when you said:

2. do you understand pointer arithmetic, arrays and how "memory" is used?
3. heap, stack?

Then I want to see if I am ready for Allegro 5. I will be developing software in a linux environment, not sure if I will use gcc or clang/llvm.

Just a thought. Let me know what you think.

Reply 22 of 42, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie

You haven't mentioned the grand daddy of it all:

https://en.m.wikipedia.org/wiki/The_C_Programming_Language

You could do a lot worse than starting with that. Much of it is still relevant today. It is clear and concise and direct from the authors of the language, and Unix itself.

If you want to learn a toolset that works everywhere, including DOS, then it's gcc and friends you want to use. Clang is great, but it doesn't target everything.

My opinion is that an API like Allegro is a substantial leap in complexity if you are not already proficient in the base language.

I'm not clear what your intended runtime targets are, do they include Dos?

My collection database and technical wiki:
https://www.target-earth.net

Reply 23 of 42, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie

No dos targets at the moment. I am planning to start with modern Linux OS and GCC.

I can't find books about gcc. They stopped making them in the late 2000s. I guess I have to go online for that.

There are many books on Linux programming that are current.

I don't like books like K&R (for C) or if we were talking Stroustrup (for C++) those are pure C, pure C++, pure language centric books.

I'm more interested in something compiler specific and books that have some examples that are intermediate enough that I can use them as a jumping off point. I agree allegro 5 is probably too difficult to tackle while I need to learn basic programming for x86-64 CPU PCs.

And then as a reference a book like K&R is so compiler agnostic you learn with pure C in lieu of say a compiler library.

Reply 24 of 42, by llm

User metadata
Rank Member
Rank
Member

C is standarized so every non ages old compiler is fully capable to be used - MSVC,clang,gcc, intel are useable on (nearly) every OS - no need to selecting something special for C development

serialShinobi wrote on 2024-04-24, 01:23:

No dos targets at the moment. I am planning to start with modern Linux OS and GCC.

what is you primary OS that you use on daily basis? if linux is not you primary system prevent to learn that too - keep focused on what you want to reach

use the freely available VS2022 Community Edition (not Visual Code) if you're on Windows because MSVC got the best debugger environment available for noobs 😀 and its fully C conform without any specials

serialShinobi wrote on 2024-04-24, 01:23:

I can't find books about gcc. They stopped making them in the late 2000s. I guess I have to go online for that.

there is no need having a special book for "learning" gcc - its just a C compiler - the difference in parameters etc. are completely unrelevant when using MSVC,clang,gcc,intel - they all can compile standard C without any problem
it was a problem 20 years ago but nowerdays they all the same

trust me: im working on multi million lines projects on multiple platforms using all these compilers - in every evil combination 😀

Reply 25 of 42, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie
llm wrote on 2024-04-24, 06:39:

no need to selecting something special for C development

I was specifying the compiler I had in mind so that you and other programmers would know which one I had in mind. I thought it might unearth insights about my situation and how to proceed. But otherwise your right that learning to program in c on a PC isn't important. Its just both windows and Linux are complex systems. Desktop Linux distro like Ubuntu usually have better documentation and others like Linux/it's popular in the development community.

MSVC got the best debugger environment available for noobs 😀 and its fully C conform without any specials

I am open to trying MSVC but I feel that GCC is something I can use for learning purposes. That's a purpose where I can catch on to things like the memory or the heap or pointer calculations, things you mentioned earlier. I need to be able to view things like that to change my circumstances of not understanding those things. I think GCC will reveal the computer organization and architectural details - the design of the system being programmed.

there is no need having a special book for "learning" gcc - its just a C compiler - the difference in parameters etc. are completely unrelevant

I love to have documentation (prefer books) for the exact compiler I am using. One day I won't care so much about the compiler. For now the feeling is nice when they are talking about a project, the source and other files, that is made for the compiler I'm using. An IDE can become unwieldy depending on the documentation you have. Some is written for an audience that wants to program at a paid expert level. And the situation can be different with IDE specific docs - written very clearly for people who need to do something simple.

trust me: im working on multi million lines projects on multiple platforms using all these compilers - in every evil combination 😀

No doubts here.

Reply 26 of 42, by spiroyster

User metadata
Rank Oldbie
Rank
Oldbie
serialShinobi wrote on 2024-04-24, 12:28:

I was specifying the compiler I had in mind so that you and other programmers would know which one I had in mind. I thought it might unearth insights about my situation and how to proceed. But otherwise your right that learning to program in c on a PC isn't important. Its just both windows and Linux are complex systems. Desktop Linux distro like Ubuntu usually have better documentation and others like Linux/it's popular in the development community.

As been mentioned, C is a language standard and so is 'fairly' platform agnostic. Compiler nuances only become relevant when you start delving into different macros and sometimes some behavioural difference, although not so much these days. Platforms only become relevant when doing system stuff outside of the application you are writing mainly wrt to filesystems (e.g. where to find config files, posix, GUI frameworks etc). When you know one platform, it's fairly trivial to apply to another.

The documentation you speak off sounds like it's more for the OS, not API? There isn't really an API for linux (other than POSIX) as it's distro dependant (although there are some standards for kernel file locations/contents etc). Theres plenty of documentation on Windows API if you do need, but tbh at first you won't need to be going anywhere near this stuff. (Also note, linux becomes distro centric outside anything beyond the terminal/console, so suddenly you are in a world of frameworks and libs which more often then not are not platform dependant anyway).

serialShinobi wrote on 2024-04-24, 12:28:

MSVC got the best debugger environment available for noobs 😀 and its fully C conform without any specials

I am open to trying MSVC but I feel that GCC is something I can use for learning purposes. That's a purpose where I can catch on to things like the memory or the heap or pointer calculations, things you mentioned earlier. I need to be able to view things like that to change my circumstances of not understanding those things. I think GCC will reveal the computer organization and architectural details - the design of the system being programmed.

I agree with llm, Visual studio debugger is the best out there, more importantly for you it is visual and allows you to step through source code easier, examine containers, memory contents etc much easier than gdb.

gcc is not a debugger, only a compiler. Easiest way to debug on linux is via gdb, but this is not 'visual', it's entirely terminal driven and although you can view source code snippets with ease, more often then not this is limited in scope and you are constanly scrolling back and forth so personally I find having to have an editor open and constanly cross-referencing source file lines with gdb. Breakpoint management and memory usages/footprint is also a hell of a lot easier in VS. In terms of pointer arithmetic etc, it's what is says and no different between the two, mem addresses and values are presented the same textual (HEX) way. Stack frames can be viewed (again terminal driven with gdb, expandable lists in visual studio), pointers will be presented mainly as hex and perhaps having a scientific calc at hand to convert hex to decimal might be useful. Again, in visual studio this is all kinda done for you. All in all VS is just easier on the eyes and much easier to navigate when debugging which would get you going much faster and allow you to concentrate of learning the skills of programming quicker. It's more intuative...

serialShinobi wrote on 2024-04-24, 12:28:

I love to have documentation (prefer books) for the exact compiler I am using. One day I won't care so much about the compiler. For now the feeling is nice when they are talking about a project, the source and other files, that is made for the compiler I'm using. An IDE can become unwieldy depending on the documentation you have. Some is written for an audience that wants to program at a paid expert level. And the situation can be different with IDE specific docs - written very clearly for people who need to do something simple.

Many IDE's will simplify the whole build process for you (hence the ancillary project files), without it you will have to manage your own areas for compilation and linking which may be difficult at first in that you may end up creating a lot of build scripts (some of the compiler command line arguments can get quite long) or end up just using makefiles (make/cmake), which tbh is probably a good thing as there is a lot more to programming than just writing source code. Tool chains and understanding the build stages is as (if not more) important than knowing how to write source code.

Compiler errors are generally fairly self-explanitory, linker errors on the other hand... not so. Many IDE's will go some way to making these linking errors somewhat more digestable.

Good luck!

Reply 27 of 42, by llm

User metadata
Rank Member
Rank
Member
serialShinobi wrote on 2024-04-24, 12:28:

I was specifying the compiler I had in mind so that you and other programmers would know which one I had in mind.

only you think its relevant in any form - its not - i need to use all of them - the differences are marginal

there are only multiple C compilers because some developers like the way clang is developed/design more then gcc, the license model or because your a employee of Microsoft or intel - they are in no way special and more or less interchangeable all the while

serialShinobi wrote on 2024-04-24, 12:28:

Desktop Linux distro like Ubuntu usually have better documentation and others like Linux/it's popular in the development community.

c0mpletely unrelevant - a online C tutorial is applyable on every OS that contains a C compiler - free/malloc, printf, arrays do not behave in any form different - not dependending on the OS nor on the compiler - because its a standard

I am open to trying MSVC but I feel that GCC is something I can use for learning purposes. That's a purpose where I can catch on to things like the memory or the heap or pointer calculations, things you mentioned earlier. I need to be able to view things like that to change my circumstances of not understanding those things. I think GCC will reveal the computer organization and architectural details - the design of the system being programmed.

all compilers contain the source code of the standard library etc. - if you mean that - the rest is completely equal - you will not be able (based on you current knowledge) to read through any of gcc sources - it will blow just you mind 😀

I love to have documentation (prefer books) for the exact compiler I am using.

its unrelevant and not available because its not needed - your asking for a book how to open the door of an decent car - but all cars are more or less open the same
- you see a difference - but there isn't

we are not talking about the difference between a Photoshop and a Excel book - more like a book about Excel 16.0.0 and Excel 16.0.1 difference - it really isn't relevant

One day I won't care so much about the compiler. For now the feeling is nice when they are talking about a project, the source and other files, that is made for the compiler I'm using.

you're code will not care from the first day on - you don't write your code for an compiler - you just use it

you need to stop thinking of how seperated these worlds are gcc,clang,msvc,windows,linux - in the C world this is all abstracted and nearly unrelevant - especially on your level - when not writing an OS or kernel drivers

Visual Studio is the most used development environment for C/C++ development on windows - you will nearly find no windows program written in C or C++ that is not compiled with it - also nearly all Games, Photoshop and everything else
- its the standard on windows - take it - its easy - there is no way in learning something wrong

you hopefully will never say "i've written an C program for gcc" but "i've written an C program that builds with any standard conform compiler out there"

Reply 28 of 42, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie

I'm convinced there is a big difference in perception here. I have just ideas. None are tested. So, I'll just go with Microsoft Visual Studio (community edition). Because after all I want to learn computer organization for use with programming. And I've learned one thing about myself - I tend to have some untested ideas - but lots of interest in trying. I know when to listen and save myself some grief. I can use GCC and it's IDE and debugger...but not if it's going to cost me in ways I'm not yet expecting.

But maybe now my process is to locate books.

So I have so far:

Tool Chain -

Windows Operating System
Microsoft Visual C/Microsoft Visual Studio

Books -

Beej's C
Effective C

Reference book?

Need a reference maybe K&R The C Programming Language and online Microsoft documentation for MSVC.

Reply 29 of 42, by llm

User metadata
Rank Member
Rank
Member

I can use GCC and it's IDE and debugger...

gcc does not come with an IDE or debugger - gcc is just a command line compiler - nothing more - all other tools like gdb and variants of IDEs are seperate developed projects by different developers

But maybe now my process is to locate books.

sorry can't help with that - im only using online resources - easier to access easier to search

here is a small 5min video tutorial about writing a tiny hello world in C installing the older VS2019 (VS2022 your using will behave excatly the same) and using the compiler on commandline or using the IDE - a very good start
don't be afraid of the huge amount of options, buttons and tools - Visual Studio is the full blown multi language IDE from microsoft - that does mean you do not need to use every feature for C development

https://www.youtube.com/watch?v=I2tEHylRPVE

watch that and start coding trivial stuff

and then do this online tutorial: https://www.programiz.com/c-programming - seems to be ok - there are so many tutorials out there...

Reply 30 of 42, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie

The only caution I would raise against learning C via something Visual studio is that it hides much of the implementation detail from you, specifically the distinct stages of preprocessor, compilation and linking.

Arguably if you want to be a C programmer you need to understand what is happening at each stage.

Still, learning C via Visual Studio versus not learning at all is not even a comparison worth making.

I can only echo the point that you don't need an implementation specific manual to learn C.

Start with the basics, something that describes C, the language (and there are several given here already - I have my favourites, others do too). They should all cover you usual.file and string handling, memory use etc. learn all that stuff once and you have learned it for 99.9% of C runtime targets.

Then, and only then, you may want to look at a more target specific API - so that would be the POSIX API (Unix systems programming by O'Reilly is an oldie but a goodie there) for Linux/Unix, the OpenWatcom C reference manual or the DJGPP reference manual for Dos... Basically implementations of the C standard library.

Once you are comfortable with those, then you can look at higher level API implementation like Allegro or libSDL.

My collection database and technical wiki:
https://www.target-earth.net

Reply 31 of 42, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie
megatron-uk wrote on 2024-04-24, 16:53:

The only caution I would raise against learning C via something Visual studio is that it hides much of the implementation detail from you, specifically the distinct stages of preprocessor, compilation and linking.

The plan so far has been to use the C language debugger from Microsoft Visual Studio. Does it not have a way to trace calls to headers/includes and is there a way visual studio logs errors with the linker for troubleshooting? We've been talking about how the debugger reveals considerable "under the hood" details.

Then, and only then, you may want to look at a more target specific API - so that would be the POSIX API

Once you are comfortable with those, then you can look at higher level API implementation like Allegro or libSDL.

So...a good jumping off point is an OS specific API? Would a book about Linux programming cover OS specific APIs including POSIX?

Prior to you mentioning the POSIX API, I was considering books on subject of "Linux programming" as a place to learn following mastering parts of C Programming that I'm missing - parts covered by a book on the language and programming (pointers, arrays, memory, stack, file I/o, etc).

Reply 32 of 42, by llm

User metadata
Rank Member
Rank
Member

you making everything soooo complicated....

you don't need to do POSIX or any OS specific programming to have contact with pointers, arrays, memory, stack, file I/o, etc - that is in normal C code - of every C program you will ever program - on Windows, Linux, only using C-Standard - even when leaving out any specific OS API - that is plain C

stop thinking about what the debugger could eventualy hide or not hide from you - the standard library code or any posix conform library code implementation is far far far more complex what you've showed in the first post - that is month if not years above you current knowledge - most developers are hardly able to read standard library implementations (its just a huge amount of code that will not give you any basic knowledge) - sorry but that ideas/thinking make no sense at all

man, im doing C, C++, High level application, Low-Level, hardware development, multi threading, reverse engineering, assembler programming, everything you can think of - for the last 25 years, full time - never need to touch anything you talking about - just start and you will see

just install VS2022 and do the tutorials in the link i send you - there is everything included pointers, arrays, memory, stack, file I/o, etc

you're planning and estimating way over the edge - without any background

Reply 33 of 42, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie
serialShinobi wrote on 2024-04-24, 18:52:
The plan so far has been to use the C language debugger from Microsoft Visual Studio. Does it not have a way to trace calls to h […]
Show full quote
megatron-uk wrote on 2024-04-24, 16:53:

The only caution I would raise against learning C via something Visual studio is that it hides much of the implementation detail from you, specifically the distinct stages of preprocessor, compilation and linking.

The plan so far has been to use the C language debugger from Microsoft Visual Studio. Does it not have a way to trace calls to headers/includes and is there a way visual studio logs errors with the linker for troubleshooting? We've been talking about how the debugger reveals considerable "under the hood" details.

Then, and only then, you may want to look at a more target specific API - so that would be the POSIX API

Once you are comfortable with those, then you can look at higher level API implementation like Allegro or libSDL.

So...a good jumping off point is an OS specific API? Would a book about Linux programming cover OS specific APIs including POSIX?

Prior to you mentioning the POSIX API, I was considering books on subject of "Linux programming" as a place to learn following mastering parts of C Programming that I'm missing - parts covered by a book on the language and programming (pointers, arrays, memory, stack, file I/o, etc).

I'm the wrong person to talk about Visual Studio can and cannot do; I'm a Unix guy, so my go-to for C is a text editor, compiler, linker and a makefile.

Most of what you describe that you want to learn should be part of the standard C library for whatever platform you choose to use.

There are some edge cases, such as most of the POSIX stuff is (these days) relatively common in most standard C libraries, not all of it is, and you won't find any of the msdos specific standard library calls in Linux.

But, these are mostly edge cases, by and large the vast majority of C compilers and standard C libraries implement most of the widely used functions.

Honestly, I would just get one of the introduction to C books, and get started... Write some simple tools, a text file parser, a search tool across your filesystem, something which saves and reloads content from a file, a sort function, a linked list library, maybe even some combination of them all where you need to dynamically allocate memory - all useful exercises that you will need to use again at some point in the future in any more complex application.

At some point you will outgrow it and then start looking for platform specific API docs.

The best way to learn is by doing, and the entry point for C these days is incredibly low with the wealth of good books and free compilers available.

My collection database and technical wiki:
https://www.target-earth.net

Reply 34 of 42, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie

Megatron & lim:

Ok. If the POSIX API is that unwieldy, that people who program for a living don't concern themselves with it than I need a different API. This is because I plan to have some kind of "deep dive" into something more challenging - but it does not need to be counter productive like OS programming or game engine development. But what API should I try next as a "jumping off point"? So far I tried game programming, specifically decoding a PCX file under MSDOS. That was counter productive and graphics programming would be. But maybe database administration with C? Edit: I just found a couple C language APIs for SQL. One was for MySQL 8.0, an API for accessing MySQL 8.0 in C.

Reply 35 of 42, by spiroyster

User metadata
Rank Oldbie
Rank
Oldbie

Honestly, you need to learn some fundamentals before any of that stuff... you will be lost in no time at all.

Do as megatron says, some simple programs to get you used to structures, processes and algorithms...

hello world...
file parser (tokeniser)...
sort function...
linked list...
double linked list...
stack (fifo, lifo etc)...
simple command line calculator (validate user inputs)...

These will keep you occupied, they will teach you fundamentals of file io, string manipulation, dynamic memory management, pointer stuff....

You will learn how to use a debugger fairly quickly since I guarantee none of these programs will work first time (apart from hello world).

Do it on windows with latest Visual Studio (use its debugger). Then take this same source code and build it on linux with an IDE perhaps (using its debugger), then build it on linux with gcc (debugging with gdb), you will soon understand what the last few posts are talking about. Better do than try to explain as it will only make sense when you try yourself.

At some point you will do something larger and then look up how to do it and the answer may say "use XXX library" or "someheader.h" from "so and so" API... thats when you start looking into which ever API and have to read up on how that API works etc ... then you will start learning more about the linking stage (static and dynamic lib linking).

POSIX was mentioned as it provides for linux much of the same functionality that Windows API provides (fundamental OS stuff)... none of this you will need until you need it, which will depend on what larger project you want to write and you'll know when you need it..

Reply 36 of 42, by megatron-uk

User metadata
Rank Oldbie
Rank
Oldbie

Yep, spot on.

My collection database and technical wiki:
https://www.target-earth.net

Reply 37 of 42, by llm

User metadata
Rank Member
Rank
Member

Ok. If the POSIX API is that unwieldy, that people who program for a living don't concern themselves with it than I need a different API. This is because I plan to have some kind of "deep dive" into something more challenging

you really don't get it - you don't need any library to learn C - and you won't learn (currently) anything from it - there are >10000 libraries out there (like Win32API, Posix, libmysql,libxml2,gmp,....never ending list for every aspect of application development) they all use C as their interface language
if you want to calculate big-int numbers with 10000 digits after point you will maybe use gmp or one of the 100 other big-num libs - if you don't need that number crunching then not... and there
are many libs that aren't even developed in C but C++ or Rust or something else but having a C compatible interface - the world is much much much larger as you think

the PCX C code is very trivial and seemingly challenging enough for you - everything else you talking about is way more complex then you currently suspect

install and try VS2022: https://www.youtube.com/watch?v=I2tEHylRPVE
and beat the shit out of this tutorial: https://www.programiz.com/c-programming and all its sub-parts (array, memory, file, ...)

after that you're able to use every of these >10000 libraries out there (after deciding the linker and the package system - there are plenty of it) - but you will be still nearly not able to understand how they work - because that needs years of experience in reading and understanding code - not only beeing firm witht the C syntax

and every pro-con argumentation or planning from your side is useless because you have no idea at all

Reply 38 of 42, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie

Thanks spiroyster. Yes I think the fundamentals of c have changed since I last tried to learn the language. The older books teach you keywords and not much else. This is analogous to learning a scripting language and using it with an API. As long as the API works so does your C. But the book I am reading now, "Effective C" from starch press starts off with all the topics you mentioned as early as Chapter 2. I believe it's because to really use C they have started teaching instead what sets it apart from a scripting language, it communicates with hardware and the CPU without the appearance of being a list of opcodes.

Reply 39 of 42, by serialShinobi

User metadata
Rank Newbie
Rank
Newbie
llm wrote on 2024-04-25, 08:34:

Ok. If the POSIX API is that unwieldy, that people who program for a living don't concern themselves with it than I need a different API. This is because I plan to have some kind of "deep dive" into something more challenging

you really don't get it - you don't need any library to learn C

and every pro-con argumentation or planning from your side is useless because you have no idea at all

I am aware that I tend to dream up ideas based on cause/effect experiences with little tested understanding.

That's why I asked my questions here. I realized I was climbing the wrong tree as I've mentioned previously.

So I am reading a book "Effective C" from starch press. It is exactly the book that will teach me to be a developer.

I can see that the libraries are for being used few developers actually make their own game engine for example or put their own database inside their blockchain project. Just examples...

Edit: and I am surprised to learn from you how prevalent C is. Glad I chose to learn this language instead of C++ or C#. I just couldn't let it go. I insisted on learning C who cared about what others were doing (popularity of C++ or relevance of JavaScript).