How do you place const in variables in program memory?

Is the an equivalent of the F macro for const int variables etc?

const int whatever PROGMEM = 42;

Actually I found this in pgmspace.h

// ****************************************************************************************
// * Typedefs
// ****************************************************************************************

typedef void PROGMEM    prog_void

typedef char PROGMEM    prog_char

typedef unsigned char PROGMEM   prog_uchar

typedef int8_t PROGMEM  prog_int8_t

typedef uint8_t PROGMEM     prog_uint8_t

But I don't get it. If I declare a variable in my .ino file using prog_uchar all is good.

But if I instead use prog_int8_t, I get a compile error saying prog_int8_t does not name a type.

What's going on here????

Well, you got the answer you were looking for but you decided to ignore it and do something on your own, why should anybody care to answer if you just don't listen to what they say?

For a single integer or even a float, why bother? It has to be transferred to SRAM to be used, so doing this forces the compiler to reserve some SRAM too.

If you just use the const keyword, then the compiler can make up its own mind where to store it most efficiently. In 59% of cases, this will be more efficient than your idea of storage and the other 41% will come out the same as your enforced storage plan. Hint: since constants aren't variable, they aren't stored in SRAM at all.

MorganS:
For a single integer or even a float, why bother? It has to be transferred to SRAM to be used, so doing this forces the compiler to reserve some SRAM too.

If you just use the const keyword, then the compiler can make up its own mind where to store it most efficiently. In 59% of cases, this will be more efficient than your idea of storage and the other 41% will come out the same as your enforced storage plan. Hint: since constants aren’t variable, they aren’t stored in SRAM at all.

Oh OK.

What is the point of the stuff in pgmspace.h about and why is the #include <avr/pgmspace.h> in Arduino.h ignored by the compiler?

I assume it is being ignored from some reason due the the compile error I am getting in my ino file.

Just curious - I will use your const suggestion.

What's going on here?

Isn't that obvious? Your code is wrong. Fix it. If you need help, POST YOUR CODE!

What is the point of the stuff in pgmspace.h about and why is the #include <avr/pgmspace.h> in Arduino.h ignored by the compiler?

It isn’t. There is something wrong with your code, your assumptions, or both.

OK well I was following this example exactly: prog_uchar sensorPin PROGMEM = 8;

If I put this in my code it compiles “const prog_uchar nRx PROGMEM = 0;”
I had to put the const in to get rid of a different compile error.

If I change it to “const prog_uint8_t nRx PROGMEM = 0;” I get the compile error where “prog_uint8_t” does not define a type.

#include <PString.h>
#include <SoftwareSerial.h>
#include <digitalWriteFast.h>
#include <EEPROMex.h>
#include <Wire.h>
#include <RealTimeClockDS1307.h>
#include <IRremote.h>
#include <TimerOne.h>
#include <CString.h>
#include <pgmspace.h>
#include "Clock.h"
#include "debug.h"

#define UNO

#ifdef UNO
const byte nIRRecPin = A3;
const byte nLEDPin = 13;
const byte nRotPhotoTransPin = 2;
const byte nRemPhotoTransPin = 3;
const byte nMaxPin = 14;
#endif

const byte nRx = 0;
const byte nTx MEM = 1;
//const byte nRx = 5;
//const byte nTx = 6;

Forget what you saw in pgmspace.h. Make that just:

const uint8_t nRx PROGMEM = 0;

Anyway, as MorganS said, you don't even need to put that in PROGMEM, it sort of gets there automatically, as long as it's a single const uint8.

#include <pgmspace.h>

Wrong!

#include <avr/pgmspace.h>

Right!

Anyway, as MorganS said, you don't even need to put that in PROGMEM, it sort of gets there automatically, as long as it's a single const uint8.

I wonder if it really does? Hmm.

PaulS:

#include <pgmspace.h>

Wrong!

#include <avr/pgmspace.h>

Right!

Tried it both ways, same result.

Granted I don't need to use pgmspace.h but......

I would still like to know why some of the typdefs are apparently not visible to the compiler when there is no apparent reason in that header file why they should not be visible.

This:

#include <avr/pgmspace.h>

const prog_uint8_t nRx PROGMEM = 0;

void setup()
{
}

void loop()
{
}

compiles on 1.0.5.

...but not 1.6.4

Arduino: 1.6.4 (Windows 7), Board: "Arduino Uno"

sketch_sep01a:3: error: 'prog_uint8_t' does not name a type
'prog_uint8_t' does not name a type

Nor on 1.6.5 running Win 7.0

The problem must be peculiar to 1.6.5 then.

I seem to now have another problem with 1.6.5

And Uno was not problem But when I plugged a mega into it I was able to upload to it OK but then, of of the blue, I started getting synch errors in the middle of the upload.

When I looked in the ports, mega was listed under both COM1 and COM40.

I tried another maga board - same problem. I tried a different USB chord - same problem. I tried a different USB port - same problem. I tried restarting Windows - same problem.

I think I need to go back to 1.0.6.

These and other problems I have noticed suggest that 1.6.5 is still a little buggy.