views:

27

answers:

3

Hello guys,

I have a weird problem in C. I have a structure and I pointed sample to that structure :

test sample;

now in the code, I call that structure through a function :

function is called something, so something(&sample) is used to point the structure in the function.

Now I need to copy values of sample to sample2 .. So I want sample2 to point to the same structure as well. So I also declared test sample2 before main, and used it as a global variable. Now when its used to point to contents in the structure in the function, sample must be called without a (*sample2).content or sample2->content. I only need to write sample2.content. I understand that this happens because sample2 declared globally... But I also get this when compiling :

comment 528 - Argument 'sample2' conceals a global declaration of the same symbol

The program runs fine, but I want to get rid of this compiler message... Why does it say that ? what does it mean ?

+1  A: 

Without seeing the code I can't be sure...

But it sounds like you have a function which is taking a 'test' which you have called 'sample2', by doing that it means you can't access the sample2 you defined globally.

Placing the code in your question would be useful.

Salgar
+1  A: 

The issue is that inside the function if you refer to the symbol sample the compiler has two things to choose from. The first is the global variable and the second is the argument you provided to the function. What the compiler is doing is alerting you to the fact that it assumes you mean the local variable and not the global one.

In general this is a recipe for grief and bugs, and you say that your code runs as intended. I cannot say how or why without looking at it in detail. The simplest answer is to just change the name of the argument to your function to something different or the global variable to something different.

Ukko
+1  A: 

Actually, you have to use the dot (.) member selector rather than the arrow (->) member selector because sample is a struct, rather than a pointer to a struct. Which has nothing to do with the error message you receive;

My guess (since I can't see your code) is that you pass sample2 as an argument to a function. This sample2 is a different sample2 than the structure you've declared globally. Since they have the same name, you will only be able to use the argument in that function, and not the global sample2.

Please consider editing your question and posting your entire code for review. There are a lot of strange assumptions in your question, and it's possible that you're relying on more than one misunderstanding.

Michiel Buddingh'