Author Topic: C: freedom from PICs  (Read 1599 times)

0 Members and 1 Guest are viewing this topic.

Offline PerranOak

  • Frequent Contributor
  • **
  • Posts: 314
  • Country: gb
C: freedom from PICs
« on: May 15, 2020, 02:41:20 pm »
I am learning C as part of my PIC "training".

what would be useful is a standalone (free) C compiler and editor that I could use to practice on without having to load programmes into the PIC or use the MPLAB simulator.

Can anyone suggest an example of such please? It would need to be for Windows.

Cheers.
Some light can never be seen!
RJD
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1149
  • Country: fi
Re: C: freedom from PICs
« Reply #1 on: May 15, 2020, 03:14:21 pm »
It's not standalone, but if you qualify for a license, Visual Studio Community is the best free Windows development environment you can get. You can use it for traditional C console applications just fine, and it has an awesome debugger.

Offline PerranOak

  • Frequent Contributor
  • **
  • Posts: 314
  • Country: gb
Re: C: freedom from PICs
« Reply #2 on: May 15, 2020, 03:50:30 pm »
Thank you.

It only seems to have C++ and I am learning C. Will that be a problem?
Some light can never be seen!
RJD
 

Offline HwAoRrDk

  • Frequent Contributor
  • **
  • Posts: 733
  • Country: gb
Re: C: freedom from PICs
« Reply #3 on: May 15, 2020, 04:22:28 pm »
I often prototype embedded code on the desktop with Visual Studio, but there are a few things you have to watch out for. Yes, it's a C++ compiler, but if you dig around in the project settings a bit, you can set an option to tell it to compile as C code only. There are also some other options you can turn off to get rid of things to do with the C++ standard library, although I forget exactly what right now (something to do with stdafx?). Another one is if you are going to use C library functions (e.g. sprintf(), etc) you have to #define _CRT_SECURE_NO_WARNINGS before you include the library headers, otherwise it will complain that you're using 'unsafe' functions.
 

Online Doctorandus_P

  • Frequent Contributor
  • **
  • Posts: 785
  • Country: nl
Re: C: freedom from PICs
« Reply #4 on: May 15, 2020, 05:07:34 pm »
I think the question is more about what IDE to use than what C compiler.

Although there are man C (and C++) standards, you will be pretty allright with anything as old as C99 compliant.
The most important thing though is that (almost) every C compiler confirms to these standards.
And that moves the question from "which C compiler" to: "Which IDE".

IDE's are a personal preference thing.
Some want all the bells and wistles they can get. Others do not want to put up with all that complexity and rather have something simple.
So you have to find a balance between features and simplicity that works with your personality.

When learning C (or C++) I would consider it to be mandatory to have a working Debugger. Settings breakpoints, stepping though the code and inspecting variables during execution is a great learning tool.

For the last few years I've been using Qt Creator for microcontroller stuff. The balance is pretty close to what I want, and you can also make simple 5 line programs with it which just outputs to the text window, and the debugger works for me.
With simple CLI interface you can concentrate on learning C (or C++) without having the load of complex graphical GUI's.

Apart from these general recommendations I can not say more, as I switched from windows to Linux the first time I saw a "blue tiles of death" screen when my PC booted and I will not be forced into some newfangled weird menu system I did not ask for.
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 2827
  • Country: us
Re: C: freedom from PICs
« Reply #5 on: May 15, 2020, 07:27:40 pm »
For someone learning the language, my opinion is the lesser the IDE footprint the better.

IDE is getting so bloated that it is far more complex than the language itself.  The step-by-step debugger is invaluable in learning, it will let the learner see what the code is doing and thus assist learning greatly; beyond that, and in particular, the way many IDE forces one to organize files, it gets in the way.
 

Offline 77algernon

  • Contributor
  • Posts: 8
  • Country: ro
Re: C: freedom from PICs
« Reply #6 on: May 15, 2020, 09:25:52 pm »
Hello!

"Pelle's C Compiler" is completely free to use and has a small footprint (installer is about 20meg). It's a complete system with IDE, debugger, assembler, resource compiler, etc. Very nice IMO.
You can find it here:

http://www.smorgasbordet.com/pellesc/index.htm

Good luck!
 
The following users thanked this post: SiliconWizard

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 1528
  • Country: us
  • Formerly SiFive, Samsung R&D
Re: C: freedom from PICs
« Reply #7 on: May 16, 2020, 08:24:59 am »
When learning C (or C++) I would consider it to be mandatory to have a working Debugger. Settings breakpoints, stepping though the code and inspecting variables during execution is a great learning tool.

I completely disagree!

That was valuable back when recompiling your program took minutes or even hours.

However trying to visually parse the information you want out of debugger output is slow and tiring, and inserting debugger actions at breakpoints using a language that is not quite the same as the language your program is in is both annoying and slows the execution of your program a lot.

Far better in these days of less than 1 second program builds to do add your temporary debugging code (including any conditional tests) right in the program itself, and use printf or cout to print precisely the information you actually want in exactly the format you want. Send the output to less or to a log file and use your favorite editor or grep or less or perl or whetever you want to search for interesting things in the log.

When finished you can delete the debugging code or else add #IFs to disable it and easily use it again at some later date if you need it.
 
The following users thanked this post: Siwastaja, Karel

Offline Karel

  • Super Contributor
  • ***
  • Posts: 1561
  • Country: 00
Re: C: freedom from PICs
« Reply #8 on: May 16, 2020, 09:56:57 am »
I never use a debugger. Not on the desktop, not in embedded.
I write temporary code (as described above) that outputs debugging info to the console, a serial port or a file.
It saves a lot of time.
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1111
  • Country: gb
  • Embedded stuff
Re: C: freedom from PICs
« Reply #9 on: May 16, 2020, 12:08:28 pm »
I've had more than one colleague who littered his code with debug printf, he never seemed to learn how to use the debugger. His code was terrible, full of bugs, he really had little clue what he was doing. So not only I had to fix his code, but also remove dozens of debugs statements so that the console was actually usable.

I quickly found a tricky bug with a watchpoint, they had been working for a couple of weeks on it. They had no idea that could be done with the debugger.

The worst thing is they provide guidance for junior engineers, who then copy those bad habits.

He is far from the only "printf maniac" I have encountered. I generally associate debug printf with bad programmers. I really have no idea why they seem to wear it as a badge of honour, it is really an admission of incompetence.

Kinda like the mechanic who turned up with just a hammer. I asked where the rest of his tools were, he explained the hammer was all he needed.
Bob
"All you said is just a bunch of opinions."
 
The following users thanked this post: ucanel

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1149
  • Country: fi
Re: C: freedom from PICs
« Reply #10 on: May 16, 2020, 12:29:48 pm »
However trying to visually parse the information you want out of debugger output is slow and tiring, and inserting debugger actions at breakpoints using a language that is not quite the same as the language your program is in is both annoying and slows the execution of your program a lot.
That depends on the size of the program. The OP was explicitly asking about something to help learn C, so the programs are probably going to be small excercises. IMO, being able to visualize eg. control flow, loop variables and so on can be helpful under those conditions.

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5344
  • Country: fr
Re: C: freedom from PICs
« Reply #11 on: May 16, 2020, 02:09:56 pm »
I never use a debugger. Not on the desktop, not in embedded.
I write temporary code (as described above) that outputs debugging info to the console, a serial port or a file.
It saves a lot of time.

Yeah. I also practically never use a debugger on embedded targets.
For 'non-embedded' targets, I rarely do either. I won't say never - I'll admit there are cases using a debugger will save you time, but I must be resorting to a debugger maybe just a few times a year or so. The exception rather than the rule for me.

There is one relatively common use of debuggers I have witnessed, and that I find wrong (and I'll admit I also used to do this as a beginner): launching a debugging session not to pinpoint a bug, but just to verify your code does what is intended. This is a very loose way of verifying code, and I consider doing that bad practice.
 
The following users thanked this post: Siwastaja

Offline HwAoRrDk

  • Frequent Contributor
  • **
  • Posts: 733
  • Country: gb
Re: C: freedom from PICs
« Reply #12 on: May 16, 2020, 03:51:52 pm »
There is one relatively common use of debuggers I have witnessed, and that I find wrong (and I'll admit I also used to do this as a beginner): launching a debugging session not to pinpoint a bug, but just to verify your code does what is intended. This is a very loose way of verifying code, and I consider doing that bad practice.

I don't know about that. I would advocate that stepping through code in a debugger to verify it's doing what's intended is a good thing. Obviously, the case of doing so for the sake of "I'm not sure what this code does", or "is this going to work?" shows immaturity and inexperience of one's language and/or tools. But, doing so to verify that there is no unexpected behaviour or side-effects is good.

For instance, you might have some code that shows you correct output, and you may even have unit tests to say that it gives the expected output for a whole slew of input cases. But! You never once stepped through the code in a debugger, following the execution flow and examining all the intermediate processes, so you missed a free() or made an off-by-one error and you have a subtle memory leak or buffer overflow that doesn't get checked by nor affects your test cases, but would cause problems down the road.

I am not a fan of developers who only ever check that the output "looks good to me", and calls it there. I consider that bad practice. On many occasions in the past I have been bitten by someone's code that externally appears to function perfectly, but in fact only happens to work accidentally or is full of side-effects.
 
The following users thanked this post: 77algernon

Offline itdontgo

  • Regular Contributor
  • *
  • Posts: 164
  • Country: gb
    • IoT Manufacturer
Re: C: freedom from PICs
« Reply #13 on: May 16, 2020, 03:52:54 pm »
After programming PICs in assembly for about 20 years I then got lumbered with a project written in C on a Raspberry Pi. I knew nothing but had to fix and update these C programs

The basic Linux C GNU is actually a decent place to start. You don't need an IDE just Notepad++ Most people have a RPi so just get started in a terminal window. To start with I was using GDB to debug the memory but I never use that now. I just output data to the terminal to see what's going on.

Google  gcc raspberry pi to get you started.

Offline PerranOak

  • Frequent Contributor
  • **
  • Posts: 314
  • Country: gb
Re: C: freedom from PICs
« Reply #14 on: May 17, 2020, 10:16:57 am »
All I really need it for is to get my head around various C concepts so I can then apply these to my PIC work.
Some light can never be seen!
RJD
 

Offline cdwijs

  • Regular Contributor
  • *
  • Posts: 57
Re: C: freedom from PICs
« Reply #15 on: May 20, 2020, 07:00:43 pm »
I think Qt is a very good platform for C code development. It's a big install, but you get a complete IDE. (compiler, editor and debugger)
It can deal with pure C.
 

Offline chriva

  • Regular Contributor
  • *
  • Posts: 102
  • Country: se
Re: C: freedom from PICs
« Reply #16 on: May 21, 2020, 07:04:08 am »
A few alternatives:

My first choice by far would be to install virtualbox and do things like this in a virtual Linux machine (Debian or Ubuntu).

sudo apt-get install build-essential

Pick editor:
1 download vscode in browser of choice and install it
2 Use gedit or nano.

create a new file and rename it to something  .c
write your code in it
gcc somefilename.c && ./a.out




Alternative two on Windows:

Here is the problem: I've run maaaaany different crosscompilers on windows for embedded targets but I don't know of any free compilers to compile native code on Windows.
You have to do your own research there.
Install any editor you'd like to use. I tend to jump between notepad++ and vscode, sometimes both at the same time :P
type away in powershell or cmd to compile and run it.

Another option would be visual studio community edition and poke around in settings to enable C in your project but their C _SUCKS_!
No c99 features so you have to declare i etc before loops.
As a matter of fact, their compiler is bitching about everything. ALL declarations must be made at the top of the function or it'll throw compile errors. :)
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 1561
  • Country: 00
Re: C: freedom from PICs
« Reply #17 on: May 21, 2020, 07:07:54 am »
Here is the problem: I've run maaaaany different crosscompilers on windows for embedded targets but I don't know of any free compilers to compile native code on Windows.

https://mingw-w64.org
 
The following users thanked this post: chriva

Offline chriva

  • Regular Contributor
  • *
  • Posts: 102
  • Country: se
Re: C: freedom from PICs
« Reply #18 on: May 21, 2020, 07:13:00 am »
I had totally forgotten about that horror but it would indeed do the job :)
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 1561
  • Country: 00
Re: C: freedom from PICs
« Reply #19 on: May 21, 2020, 07:41:23 am »
I had totally forgotten about that horror but it would indeed do the job :)

It's indeed far from ideal, but I have to use it for one project where users demand a windows version.
The other option is no windows version at all and they use Linux, because I refuse to use any microsoft tools.
So, Mingw it is...
 

Offline cedric!

  • Contributor
  • Posts: 8
  • Country: nl
Re: C: freedom from PICs
« Reply #20 on: May 21, 2020, 08:18:30 am »
I had totally forgotten about that horror but it would indeed do the job :)

It's indeed far from ideal, but I have to use it for one project where users demand a windows version.
The other option is no windows version at all and they use Linux, because I refuse to use any microsoft tools.
So, Mingw it is...

I routinely use the Qt IDE to hide the horror that's mingw from me.
 

Offline chriva

  • Regular Contributor
  • *
  • Posts: 102
  • Country: se
Re: C: freedom from PICs
« Reply #21 on: May 21, 2020, 08:28:16 am »
Their IDE is almost as bad as the arduino editor.
People have complained for YEARS that they should have tabs like literally everyone else. You think they listen? -NO!  |O
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 1561
  • Country: 00
Re: C: freedom from PICs
« Reply #22 on: May 21, 2020, 09:47:04 am »
I had totally forgotten about that horror but it would indeed do the job :)

It's indeed far from ideal, but I have to use it for one project where users demand a windows version.
The other option is no windows version at all and they use Linux, because I refuse to use any microsoft tools.
So, Mingw it is...

I routinely use the Qt IDE to hide the horror that's mingw from me.

I never use an IDE. I always use Kate on Linux for all development and testing, also for Qt. I don't even use *.ui files for graphical interfaces.
I only use Mingw from the windows commandline to recompile the source in order to offer also a windows version of the project.
But that's only after the Linux version completely done and tested. That way I keep my windows sessions as short as possible  >:D
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2052
  • Country: gb
Re: C: freedom from PICs
« Reply #23 on: May 21, 2020, 09:48:03 am »
I use CLion from JetBrains for cross platform development.  (I am a JetBrains fan-boy)

If you are a student... check out https://education.github.com/pack

An alternative is Visual Studio Code (I assume it has some add-ins) or Visual Studio.

Setting up a C/C++ development environment is a PIA.

PS
I spend lots of my time when developing host programs in the debugger, on the target it tends to be printf and pin wiggling.
 
The following users thanked this post: chriva

Offline chriva

  • Regular Contributor
  • *
  • Posts: 102
  • Country: se
Re: C: freedom from PICs
« Reply #24 on: May 21, 2020, 09:51:44 am »
on the target it tends to be printf and pin wiggling.

You're lucky :D -nostdlib is par for the course when I have to do it so everything has to be from scratch. Granted, setting up a rudimentary printf is quite easy. Just send the string byte-for-byte until a 0 is encountered :)
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2052
  • Country: gb
Re: C: freedom from PICs
« Reply #25 on: May 21, 2020, 10:31:10 am »
You're lucky :D -nostdlib is par for the course
Actually I meant writing serial bytes... I used 'printf' as a generic term rather than a function call.  ;)
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 1528
  • Country: us
  • Formerly SiFive, Samsung R&D
Re: C: freedom from PICs
« Reply #26 on: May 21, 2020, 11:54:11 pm »
on the target it tends to be printf and pin wiggling.

You're lucky :D -nostdlib is par for the course when I have to do it so everything has to be from scratch. Granted, setting up a rudimentary printf is quite easy. Just send the string byte-for-byte until a 0 is encountered :)

Well ... that's puts() rather than printf(). A printf() that can handle %s and %d without field widths or number bases is about a dozen lines of code. Adding hex and octal and minimum widths with space or zero padding (99% of what people use) it's probably 50 to 100 lines of code.
 

Offline chriva

  • Regular Contributor
  • *
  • Posts: 102
  • Country: se
Re: C: freedom from PICs
« Reply #27 on: May 22, 2020, 12:07:43 am »
You could even call the function printfart() if you wanted :p

On a more serious note tho: You are indeed correct.
I tend to use the term as an umbrella for all of them for some stupid reason. -sorry :)
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3197
  • Country: us
Re: C: freedom from PICs
« Reply #28 on: May 22, 2020, 02:40:17 am »
Quote
I had totally forgotten about that horror
Mingw is a horror?  I recall it being relatively trivial to install.  I was just using the CLI tools; presumably that would be sufficient for "learning the basics of C"
(or, there is apparently VS Code support for mingw:  https://code.visualstudio.com/docs/cpp/config-mingw ) (although my very limited experience with VS Code seems to indicate that it's harder to set up than a CLI based build/compile/debug system...   Perhaps not ideal for short and sweet C training programs...)

Quote
I never use a debugger. Not on the desktop, not in embedded.
And... Are you just learning a new language?
« Last Edit: May 22, 2020, 02:50:18 am by westfw »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3197
  • Country: us
Re: C: freedom from PICs
« Reply #29 on: May 22, 2020, 05:55:47 am »
oh, If you sort-of think that MPLABX is OK aside from the upload/reprogram/etc cycle, you might want to try installing Netbeans with mingw for "local" compilation.  MPLABX is built on top of NetBeans, and they might be similar (depending on how much customization Microchip has done.)https://netbeans.org/community/releases/80/cpp-setup-instructions.html#compilers_windows
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 2459
  • Country: gb
Re: C: freedom from PICs
« Reply #30 on: May 23, 2020, 01:30:17 pm »
I have Code::Blocks installed on all the machines I develop on, it will install GCC for you (if you download the full package) and it has a pretty decent IDE.  I use it for developing and unit testing algorithms/numerical functions and for knocking up small utilities for creating/reading files etc.
 
The following users thanked this post: NivagSwerdna

Offline chriva

  • Regular Contributor
  • *
  • Posts: 102
  • Country: se
Re: C: freedom from PICs
« Reply #31 on: May 23, 2020, 01:45:15 pm »
Had no clue they were still around
If they're anything like they used to I can definitely vouch for this suggestion :)
 

Offline Jan Audio

  • Frequent Contributor
  • **
  • Posts: 455
  • Country: nl
Re: C: freedom from PICs
« Reply #32 on: June 27, 2020, 02:58:19 pm »
Go for programming DOS.
It is console window, very easy.
Just about as simple as programming a PIC.

C++ is also good, just dont use classes.
For the rest you can learn, it is about the same.
« Last Edit: June 27, 2020, 02:59:50 pm by Jan Audio »
 

Offline pidcon

  • Contributor
  • Posts: 12
  • Country: my
Re: C: freedom from PICs
« Reply #33 on: June 28, 2020, 10:39:19 am »
There are online C compilers which you could try out. It's based on either gcc or clang.

https://www.onlinegdb.com/
https://repl.it/languages/C
https://www.jdoodle.com/c-online-compiler/

Otherwise, if the compiler has to be in the local Windows computer, I would suggest the C/C++ compiler from Embarcadero. It was used to be Borland's C/C++ compiler. No installation required, just set the user PATH and you're good to go. There are some features in the old compiler which is no longer necessary in the modern compilers.

https://www.embarcadero.com/free-tools/ccompiler

All the best!
 

Online ebclr

  • Super Contributor
  • ***
  • Posts: 2106
  • Country: 00
Re: C: freedom from PICs
« Reply #34 on: June 29, 2020, 01:18:19 pm »
 

Offline garethw

  • Regular Contributor
  • *
  • Posts: 85
  • Country: gb
Re: C: freedom from PICs
« Reply #35 on: June 30, 2020, 10:12:27 pm »
Linux user here, so GCC, make, and the like. I use VSCode as my editor.
Father
Husband
MENG Electronic Engineering student
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1459
  • Country: dk
Re: C: freedom from PICs
« Reply #36 on: July 01, 2020, 05:10:36 pm »
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 2067
  • Country: ca
Re: C: freedom from PICs
« Reply #37 on: July 05, 2020, 04:43:04 pm »
If you want to learn C, I would just take a text editor and a command line compiler. You can use GCC, or download free C/C++ compiler from Microsoft. Write small examples which cover the aspects you want to learn. I don't think a debugger will help here, but it might be nice to be able to look at expanded macros (which can be done by using --save-temps with GCC and watching the .i file). This is because most newbies misunderstand macros.

I would spend couple weeks writing small test programs and watching how they work. Most of things in C are straightforward. But you need to take some time to understand concepts. For example integer promotion is often neglected, but it means a lot, especially for small MCUs where C uses 16-bit integers. Other things which newbies have problems with are logic vs bitwise operations, understanding scope and duration, understanding sequence points, using pointers, understanding how structs are packed. IMHO, it is important to get a good grasp on basic concepts from the onset.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf