Shop OBEX P1 Docs P2 Docs Learn Events
C4SX: Why use C? Here is a sample C program that runs on both the SX48 and Win — Parallax Forums

C4SX: Why use C? Here is a sample C program that runs on both the SX48 and Win

RW SenserRW Senser Posts: 61
edited 2007-08-13 04:28 in General Discussion
Greetings. If you are interested in running C on the SX chips, the attached sample C program might be of interest to you.

Attached is a sample C program, called prime48.c, that counts the number of prime numbers between
2 and 100, and prints out the answer (which is 25).

What is interesting is that this exact same program, unmodified, also works under the Windows VC6 C compiler.· The Windows exe file is included in the attached zip.· Note that, with the SX48, ·th results are output with the I/O functions in the C4SX sxio.h library.· This SX prgm·can also be run on the· SX48 without serial support (let the debugger stop at the break point....).

This program is a bit of nonsense as who would want to·compute/find primes on a microcontroller??· But, it also makes a small point:· What other language can be used to write programs that can be tested under Windows and, unmodified, run on the SX?·· /* in other words, this is a very shameless plug for using C .... */··

On a serious note, this all works by using C #ifdef .... #endif sequences to keep the SX and Windows-specific code seperated.· In other words, the code is ported to both the SX and Windows platforms.

RW Senser
Sign In or Register to comment.