No Likey const char* =-/

I'm working on updating some legacy code and have run into an error I can't seem to remedy.

Compiling Error:
1
2
client.C:550: error: expected unqualified-id before string constant
client.C:550: error: expected initializer before string constant


A small portion of the code Code:
1
2
3
4
5
6
7
8
9
10
11
void Get_client_name(char *p)
{
    char record[500];
    FILE *work_fp;

    const char* CAL = "/user/data/client.affiliate.list";  // Line 550
    if((work_fp = fopen(CAL, "r")) == NULL)
    {
        printf("Abend - Open failed: %s\n\n", CAL);
        exit(1);
    }


Any suggestions?
Nothing is wrong with that code. The only thing I can think of that would be causing the error is CAL being a macro.

All-caps is kind of a red flag.

Try renaming CAL to something else and see if it works (try to pick something that isn't all-caps).
Last edited on
Actually, CAL was a macro but I'm trying to localize it. (the whole "legacy code" thing...haha)

It is declared locally in several other places but there are no longer any global references to it.

Is there anything else it could be?
Actually, CAL was a macro but I'm trying to localize it


Did you remove all the CAL macro definitions? maybe there was more than one and you missed it?

An easy way to test this would be to do this just before line 550:

1
2
3
#ifdef CAL
#error "There is a lingering CAL macro somewhere"
#endif 


If you get the error, then you missed a macro.

Is there anything else it could be?


There's always the possibility, but in this case I really don't think so. If there's no macro, then there's nothing wrong with line 550 and it should be compiling OK.

If it was some other kind of name conflict the error woud be different... but the error you're getting suggests the macro is replacing CAL with garbage.
Last edited on
Topic archived. No new replies allowed.