Can I use "C" language inside a sketch?

My subject looks stupid. I have lots of C experience and I have played with many uChip environments. I have 2 weeks experience with Arduino.

I see that it is very C-like which means I can pick it up instantly. I would describe it as C-light, missing many things.

I have been reading as much as I can on this forum and something stands out as odd. Occasionally I see references to commands, functions or syntax that is not in the arduino online guide.

Is the online guide out-dated or are you guys somehow passing code to the back-end GCC compiler via some sort of compiler define?

I am thinking timers, interrupts and direct pin I/O (for speed and accuracy). I realize that the arduino is a safe environment and I am ok with that, I am simply trying to determine if I missed something.

ps: I purchased the Massimo book from Amazon.com, I hope he makes a few bucks off it because of this successful project!

Hi Mark,

Think of arduino specific code as an abstraction layer sitting on top of C. Its actually sitting on top of C++, with the C++ part only subtly visible. There is nothing stopping you using C and C++ code on the arduino, but stuff intended to be shared with the arduino community tends to avoid most of the complex stuff.

Most here try to get the job done using the simplest appropriate syntax and only get under the covers when necessary. A lot of the complex stuff is hidden in Arduino libraries, which you may have noticed are C++ classes.

Have a look at the avr-gcc compiler documentation if you are inclined to get your hands dirty.

Have fun!

Thanks for the reply. I think I was looking at a library when I saw what appeared to be non-Arduino stuff. I'll look closer at libraries. I noted the page on the AVRC lib and its functions. It seems I can get access to some fairly advanced stuff by calling those functions.

You can do use almost everything C (and most of C++) has available - within the limitations of the architecture and limited memory of the AVR chips we use.

fascinating... I tried this and it worked... This adds a whole new set of fun commands to play with!

typedef struct mystruct
{
int a;
int b;
int c;
};

mystruct mys;

void setup()
{

}

void loop()
{

mys.a = 1;
mys.b = 2;
mys.c = 3;
}

I have some AVR Butterflys coming in and I think I'll create a library to use the onboard features from within the Arduino enironment.

Yes, mem is right. I certainly wouldn't characterize the Arduino language as "C-light". :slight_smile: It was very liberating to me when I realized that, a few bugaboos and resource constraints aside, I could do anything that C/C++ permits.

Mikal

You have all of C (and much of C++) available to you within your Arduino sketch. Much of it is skipped in the DOCUMENTATION to make things easier to understand for beginners, but nothing is actually "turned off."

Writing C code and having the C++ compiler deal with it seems to work fine; that's what I've been doing !

Thanks guys. This is good news and I feel stupid.

Why?

I was trying to decide... Do I use avr-gcc or arduino sketch? Arduino seemed to be the fast way to get started even though the docs only showed a limited set of C stuff.

It now appears that I have been using gcc for the past 2 weeks and did not know it. I like it when I make those types of mistakes!

I went nuts and ordered LOTS of various bits. Some kits (built 3 already) and some bare boards, shields and boarduino things. I also have a butterfly and ethernet shield coming in. I could show in class how to construct an IP stack. It seems the supplied library does not support DHCP. Might be a good class project to add support for DHCP.

DHCP would be awesome. I think there are some avr implementations for the W5100 on the ethernet shield, it shouldn't be too hard to get them working with the Ethernet library.