Help with typedef

I have programmed for a lifetime, but I only started using C when I came across the Arduino. When I need to advance my knowledge of Arduino programming I go look up the C or C++ construct I need, and get it working. So I have reached a point where I would like to define a data type, so that I may pass that type into a function, and define the function result and the same type.

But here's whats happening. In the following code, the Arduino compiler is completely happy with my typedef, my decalartions, and my operations until I attempt to create the function "concat"at the bottom. Then it tells me that "FString does not define a type." Is this a shortcoming of the Arduino variant of C, and if not, what does it take to get this type recognizable? Do I have to pass references by pointer, or what?

Thanks in advance for any help with this.

John Doner

typedef char FString[30];

FString s1, s2;

void setup() { s1[0] = 'a'; s1[1] = 'b'; s2[0] = 'c'; s2[1] = 'd'; }

void loop() { s1[0] = s2[1]; s2[0] = s1[1]; }

FString concat() {

}

I don't know. Maybe typedef doesn't work for arrays. I have never used it for an array to the best of my recollection. Only for structs and for renaming basic types.

What do you think that your typedef is supposedly creating there ?

A type which consists of an array of 30 chars ?

Or an array of 30 of … something … ??

I am not so sure that your compilation is as happy as you think it might be.

You can't typedef an array - an array isn't an atomic data type.

You can, however, create a struct with an array in it:

typedef struct {
  char data[30];
} FString;

FString S1, S2;

void setup()
{
       s1.data[0] = 'a';
       s1.data[1] = 'b';
      s2.data[0] = 'c';
      s2.data[1] = 'd';
}

void loop()
{
     s1.data[0] = s2.data[1];
     s2.data[0] = s1.data[1];
}

 FString concat()
 {
    strcat(s1.data, s2.data);
    return s1;
}

However, in these situations, it can me more useful to create a class rather than a struct, and embed the functions for performing operations on the data within the class itself.