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

0 Members and 1 Guest are viewing this topic.

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2107
  • 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.  ;)
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 1619
  • 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: 3245
  • 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: 3245
  • 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: 2514
  • 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: 465
  • 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: 28
  • 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!
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 2122
  • 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: 1478
  • Country: dk
Re: C: freedom from PICs
« Reply #36 on: July 01, 2020, 05:10:36 pm »
 

Offline NorthGuy

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

Offline pidcon

  • Contributor
  • Posts: 28
  • Country: my
Re: C: freedom from PICs
« Reply #38 on: July 21, 2020, 02:30:30 pm »
First-time learners of C (or any programming language) should use an Integrated Development Environment (IDE). It will make your life easier, so that you focus on what is truly important... learning. Not having to deal with system settings, command line settings, terminals, etc. in the early stage of your studies is a good thing. Once you have mastered the language basics and also the environment on which the compiler operates, then you can look at setting up command line compiler tools.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3245
  • Country: us
Re: C: freedom from PICs
« Reply #39 on: July 21, 2020, 02:56:11 pm »
“If your problem  is that you don’t know which compiler to use, and you decide to use an IDE - now you have TWO problems!”

 
The following users thanked this post: NivagSwerdna, NorthGuy

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5447
  • Country: fr
Re: C: freedom from PICs
« Reply #40 on: July 21, 2020, 04:40:49 pm »
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"

Not sure what you call "mingw" these days. Things have evolved, and the equivalent CLI environment is now MSYS2, which is fine. https://www.msys2.org/
It's meant to more or less "emulate" a POSIX environment and a Bash shell. If you're used to developing on Linux, or actually need autotools/autoconf, it works fairly well. If you need to build software that use "configure" on Windows, it's the way to go. It has a package manager too, so keeping it up to date is a breeze.

Now if you're fine with basic Windows CLI tools, you don't need MSYS2. You can download various binaries for GCC that don't require MSYS2, and you can also find "make" and other similar tools that will work in a basic Windows console. A nice alternative to the Windows terminal is ConEmu: https://conemu.github.io/en/
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 1619
  • Country: us
  • Formerly SiFive, Samsung R&D
Re: C: freedom from PICs
« Reply #41 on: July 21, 2020, 10:19:41 pm »
First-time learners of C (or any programming language) should use an Integrated Development Environment (IDE). It will make your life easier, so that you focus on what is truly important... learning. Not having to deal with system settings, command line settings, terminals, etc. in the early stage of your studies is a good thing. Once you have mastered the language basics and also the environment on which the compiler operates, then you can look at setting up command line compiler tools.

I disagree completely!

Code: [Select]
sudo apt install gcc
<use an editor to create hello.c>
gcc hello.c -o hello
./hello

I don't know what could be easier! Certainly not any IDE I know of.

Sure, you're not going to somehow guess you need the above commands. That's what a tutorial is for. This message is sufficient.
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 1775
  • Country: fi
    • My home page and email address
Re: C: freedom from PICs
« Reply #42 on: July 22, 2020, 02:04:33 pm »
I fully agree with brucehoult above.

And, at some point, follow up with a couple of quick fifteen-minute sessions on Makefiles, starting with say my "default",
Code: [Select]
CC      := gcc
CFLAGS  := -Wall -O2
LDFLAGS := -lm
PROGS   := example

all: $(PROGS)

clean:
rm -f *.o $(PROGS)

%.o: %.c
$(CC) $(CFLAGS) -c $^

example: main.o other.o
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
and about running sed -e 's|^  *|\t|' -i Makefile to fix indentation to use tabs instead of spaces.  (There are two spaces between ^ and * there.)

Then, a couple of examples on how to debug complex data structures by outputting their structure description in Graphviz dot format, and visualising those.

Then, it would be (in my opinion) time to visit Data Structures and Algorithms.   :)
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 2514
  • Country: gb
Re: C: freedom from PICs
« Reply #43 on: July 23, 2020, 09:36:46 am »
I disagree completely!

Code: [Select]
sudo apt install gcc
<use an editor to create hello.c>
gcc hello.c -o hello
./hello

I don't know what could be easier! Certainly not any IDE I know of.

Sure, you're not going to somehow guess you need the above commands. That's what a tutorial is for. This message is sufficient.

Your instructions fail when tested on the most popular desktop operating system in the world.
 
The following users thanked this post: Bassman59

Offline Psi

  • Super Contributor
  • ***
  • Posts: 7623
  • Country: nz
Re: C: freedom from PICs
« Reply #44 on: July 23, 2020, 09:42:25 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 agree that real time debugging is useful.
But. When i encounter a problem that confuses me so much that i reach for the debugger i often find that the problem does not occur while stepping through the code.
The fact of using the debugger makes the problem go away.

It's incredibly annoying and usually ends up being some memory corruption.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline pidcon

  • Contributor
  • Posts: 28
  • Country: my
Re: C: freedom from PICs
« Reply #45 on: July 23, 2020, 09:44:08 am »
First-time learners of C (or any programming language) should use an Integrated Development Environment (IDE). It will make your life easier, so that you focus on what is truly important... learning. Not having to deal with system settings, command line settings, terminals, etc. in the early stage of your studies is a good thing. Once you have mastered the language basics and also the environment on which the compiler operates, then you can look at setting up command line compiler tools.

I disagree completely!

Code: [Select]
sudo apt install gcc
<use an editor to create hello.c>
gcc hello.c -o hello
./hello

I don't know what could be easier! Certainly not any IDE I know of.

Sure, you're not going to somehow guess you need the above commands. That's what a tutorial is for. This message is sufficient.

Fair enough. I've put in my 2 cents as a lecturer. Anyway, the OP is in good hands with the enormous support from the community experts. Signing out.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 1619
  • Country: us
  • Formerly SiFive, Samsung R&D
Re: C: freedom from PICs
« Reply #46 on: July 23, 2020, 10:28:12 am »
I disagree completely!

Code: [Select]
sudo apt install gcc
<use an editor to create hello.c>
gcc hello.c -o hello
./hello

I don't know what could be easier! Certainly not any IDE I know of.

Sure, you're not going to somehow guess you need the above commands. That's what a tutorial is for. This message is sufficient.

Your instructions fail when tested on the most popular desktop operating system in the world.

Quite possibly. The tastes of the majority are notoriously bad. I don't drive a Toyota (or VW) either, though I'm sure many people are happy with them.

No doubt there is some equally easy equivalent there.  I have no idea, as I don't use it. I heard they added Linux and bash and so forth to it now -- surely there is a package manager? There is on the Mac -- there the first line would be "port install gcc" (well there are a couple of alternatives, just as there are others such as rpm on different Linuxes).

The key is just to get the right instructions for what you're using. That's going to be just as much an issue installing an IDE as installing a command line compiler, so is irrelevant to the IDE vs command line discussion.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 1619
  • Country: us
  • Formerly SiFive, Samsung R&D
Re: C: freedom from PICs
« Reply #47 on: July 23, 2020, 10:50:04 am »
First-time learners of C (or any programming language) should use an Integrated Development Environment (IDE). It will make your life easier, so that you focus on what is truly important... learning. Not having to deal with system settings, command line settings, terminals, etc. in the early stage of your studies is a good thing. Once you have mastered the language basics and also the environment on which the compiler operates, then you can look at setting up command line compiler tools.

I disagree completely!

Code: [Select]
sudo apt install gcc
<use an editor to create hello.c>
gcc hello.c -o hello
./hello

I don't know what could be easier! Certainly not any IDE I know of.

Sure, you're not going to somehow guess you need the above commands. That's what a tutorial is for. This message is sufficient.

Fair enough. I've put in my 2 cents as a lecturer. Anyway, the OP is in good hands with the enormous support from the community experts. Signing out.

Oh, sting!

I guess the mean reply is I've taught a few people to program as well, but without the goal of failing half of them in the first semester :-)

If you'd said a debugger and single-stepping and so on is useful for beginners then you'd have a point, except there are perfectly good stand-alone debuggers, including GUI ones, which you can mix and match. It's not necessary or even all that useful to have an *integrated* environment.

I also don't use C as the initial language. Or Java or Python either. They all are far too magical, hiding the details of what is really going on and making it very difficult for the student to form a correct and useful mental model.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3290
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: C: freedom from PICs
« Reply #48 on: July 23, 2020, 11:14:27 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.

That simply means you have never done any serious software work.  Blinking LED displays sure may not require any in-circuit debugger, but a real-time DSP application running with 10 DMA channels, ethernet and a GUI interface under a RTOS absolutely requires a debugger and profiler.

Discouraging beginners from using and learning how and when to use such powerful tools from the beginning is silly.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3290
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: C: freedom from PICs
« Reply #49 on: July 23, 2020, 11:22:52 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.

See my response above.

1 second builds do not happen with complex projects.

Adding debug code to a timing and resource tight embedded application  (what is called "intrusive debugging") is simply not possible in many complex applications. That is what uneducated arduino folks do, because they don't know any better (and even can't learn any better because people who think like you) . And that is where a skilled software engineer brings up his box of tools for non-intrusive debugging.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf