Redefining AjPStr

Peter Rice pmr at
Tue Jul 15 10:20:08 UTC 2003

A small C compiler problem has appeared in EMBOSS - I tried to add 
"const" definitions to functions so we could be sure which ones make 
changes to the objects we pass.

Unfortunately, "const AjPStr" does not work as expected in any compiler 
I tried. The reason is that "const" has to see a "*" to know it is 
working on a pointer.

To fix this, I will try redefining AjPStr using #define.

Existing source code is not affected, except ...

1. The following (deprecated) syntax will break:

   AjPStr astring, bstring;

You have to use:

   AjPStr astring;
   AjPStr bstring;

2. You may occasionally see "AjOStr*" in compiler messages where you saw 
"AjPStr" before.

The old AjPStr definition was:

typedef struct AjSStr {
   char *Ptr;
} AjOStr, *AjPStr;

The new definition will be:

typedef struct AjSStr {
   char *Ptr;
} AjOStr;
#define AjPStr AjOStr*

Now we can use "const AjPStr" in function prototypes and check the 
string is safe. AjPSeq and other AJAX types are more tricky as "const" 
only goes down one level, so the compiler will not check everything.

For example;

AjBool     ajStrAssS  (AjPStr* pthis, const AjPStr str);
ajint      ajStrLen(const AjPStr thys);

The changes will be committed to CVS today or tomorrow.


More information about the emboss-dev mailing list