473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

redeclaration of 'p' with no linkage

#include <stdio.h>
int main(void)
{
int i, j, *p;
i = 25;
j = 100;
int *p = &i;
}

When I compiled the above code with gcc I goth the message :
"redeclaration of 'p' with no linkage" .
What does this mean. Can You please explain?

Aug 19 '07 #1
6 17792
Ravi wrote:
>
#include <stdio.h>
int main(void)
{
int i, j, *p;
i = 25;
j = 100;
int *p = &i;
}

When I compiled the above code with gcc I goth the message :
"redeclaration of 'p' with no linkage" .
What does this mean.
It means that p has no linkage and that you declared p twice.
Can You please explain?
It's easier just to fix the code:

#include <stdio.h>

int main(void)
{
int i, j, *p;

i = 25;
j = 100;
p = &i;
}

--
pete
Aug 19 '07 #2
On Sun, 19 Aug 2007 14:43:13 -0000, in comp.lang.c , Ravi
<ra*********@gmail.comwrote:
>#include <stdio.h>
int main(void)
{
int i, j, *p;
here you declared p as a pointr to an int.
i = 25;
j = 100;
int *p = &i;
here, you tried to declare it again.

Both declarations don't specify the linkage - that is, they don't say
that the object is extern (external linkage) or static (internal
linkage) .

Such objects have 'no linkage' and you can't have two of them in the
same scope. See 6.2.2 of the Standard.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Aug 19 '07 #3
Ravi wrote:
>
#include <stdio.h>
int main(void) {
int i, j, *p;
i = 25;
j = 100;
int *p = &i;
}

When I compiled the above code with gcc I goth the message :
"redeclaration of 'p' with no linkage" .
What does this mean. Can You please explain?
You already declared it in the first line.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com

Aug 19 '07 #4
Mark McIntyre wrote:
>
On Sun, 19 Aug 2007 14:43:13 -0000, in comp.lang.c , Ravi
<ra*********@gmail.comwrote:
#include <stdio.h>
int main(void)
{
int i, j, *p;

here you declared p as a pointr to an int.
i = 25;
j = 100;
int *p = &i;

here, you tried to declare it again.

Both declarations don't specify the linkage - that is, they don't say
that the object is extern (external linkage) or static (internal
linkage) .

Such objects have 'no linkage' and you can't have two of them in the
same scope. See 6.2.2 of the Standard.
Does that mean that this should be valid?

void foo(void)
{
static int *p;
int i;
extern int *p = &i;
}

My compiler doesn't allow it. (Ditto with other combinations of
static/extern/none.) They all give "'p' : redefinition".

(Not that I would ever knowingly use such a construct.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Aug 20 '07 #5
Kenneth Brody wrote:
Mark McIntyre wrote:
>>
On Sun, 19 Aug 2007 14:43:13 -0000, in comp.lang.c , Ravi
<ra*********@gmail.comwrote:
>#include <stdio.h>
int main(void)
{
int i, j, *p;

here you declared p as a pointr to an int.
i = 25;
j = 100;
int *p = &i;

here, you tried to declare it again.

Both declarations don't specify the linkage - that is, they don't say
that the object is extern (external linkage) or static (internal
linkage) .

Such objects have 'no linkage' and you can't have two of them in the
same scope. See 6.2.2 of the Standard.

Does that mean that this should be valid?

void foo(void)
{
static int *p;
int i;
extern int *p = &i;
}

My compiler doesn't allow it. (Ditto with other combinations of
static/extern/none.) They all give "'p' : redefinition".
In this case, static does not imply internal linkage. A block-scope object
defined with the keyword 'static' has no linkage. A file-scope object
defined with the keyword 'static' has internal linkage.

Additionally, objects with static storage duration must have constant
initialisers, which &i is not, and block-scope declarations of objects with
linkage may not even have any initialiser at all.

But your compiler should not object to

void foo(void)
{
extern int *p;
extern int *p;
}

nor to

static int *p;
void foo(void)
{
extern int *p;
extern int *p;
}
Aug 20 '07 #6
On Mon, 20 Aug 2007 14:31:47 -0400, in comp.lang.c , Kenneth Brody
<ke******@spamcop.netwrote:
>Mark McIntyre wrote:
>>
Such objects have 'no linkage' and you can't have two of them in the
same scope. See 6.2.2 of the Standard.

Does that mean that this should be valid?

void foo(void)
{
static int *p;
int i;
extern int *p = &i;
}

My compiler doesn't allow it.
Interesting - I think that this ought to be allowed by 6.2.2p4,
though I'm happy to be corrected. Is this a C89 vs C99 thing?

"For an identifier declared with the storage-class specifier extern in
a scope in which a prior declaration of that identifier is visible, if
the prior declaration specifies internal or external linkage, the
linkage of the identifier at the later declaration is the same as the
linkage specified at the prior declaration. If no prior declaration is
visible, or if the prior declaration specifies no linkage, then the
identifier has external linkage."
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Aug 20 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: qazmlp | last post by:
const has internal linkage in C++, but external linkage in C. Am I right ? But, linker reports multiply-defined error if the following header is included in multiple .cpp files. //...
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
20
by: Grumble | last post by:
Hello everyone, As far as I understand, the 'inline' keyword is a hint for the compiler to consider the function in question as a candidate for inlining, yes? What happens when a function with...
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
5
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
3
by: al.cpwn | last post by:
do static and inline functions or members have internal linkage? I have been reading this newsgroup on google and found conflicting ideas. Can someone please help me understand why in some places...
13
by: fctk | last post by:
source: http://rm-f.net/~orange/devel/specifications/c89-draft.html#3.1.2.2 there are two passages in this paragraph i can't fully understand: 1) "If the declaration of an identifier for an...
3
by: DhaneshNair | last post by:
Hi all, I hav a file which is actually linkage file (used as an reference interface between c and c++ files). And this file has got two structures in it .. When i include this file directly i...
3
by: silentcoast | last post by:
Alright im not sure why but im getting a "member function redeclaration not allowed" error when I to compile this simple program. main.cpp #include "main.h" CNetwork net; int main() {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.