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

0 Members and 1 Guest are viewing this topic.

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • 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.
You can release yourself but the only way to go is down!
RJD
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • 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 PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • 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?
You can release yourself but the only way to go is down!
RJD
 

Offline HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1471
  • 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.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3341
  • 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.
 

Online Rick Law

  • Super Contributor
  • ***
  • Posts: 3439
  • 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

  • Newbie
  • Posts: 9
  • 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: 4028
  • Country: nz
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: 2217
  • 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: 1093
  • 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: 1198
  • 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.

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14439
  • 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

  • Super Contributor
  • ***
  • Posts: 1471
  • 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: 167
  • 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 PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • 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.
You can release yourself but the only way to go is down!
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: 2217
  • 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: 2217
  • 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: 31
  • 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: 2217
  • 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: 2495
  • 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 :)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf