473,327 Members | 1,936 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,327 software developers and data experts.

Error E2349 tester.c 29: Nonportable pointer conversion

Please have a look at the code below

My problem is the error message "Nonportable pointer conversion", so far as
I can tell there is no pointer conversion occuring here so I am assuming it
is something implicit. The error is associated with the assignment {
&MenuItemList }, when delcaring the mit_ZoneSelectMenu structure.

I am using borland bcc32 the command line compiler which seems pretty good,
I just dont understand this issue.

#include <stdio>

#define _LEN_A_ 16 // this is minimum

typedef struct {
u8 ItemName[(_LEN_A_ - 1)];
boolean (*ItemHandler)( u8 Token );
} MenuItemT;

typedef struct {
u8 string_a[_LEN_A_];
MenuItemT * pItemList;
u8 ItemCount;
} MenuT;

static boolean fn_a( u8 token );
static boolean fn_b( u8 token );

static volatile MenuItemT MenuItemList[] = {
/* "Item Name ", Item Handler Function */
{ "Item A" , &fn_a }, // Zone A
{ "Item B" , &fn_b }, // Zone B
{ NULL , NULL }
};

static volatile MenuT mit_ZoneSelectMenu[] = {
{ "Menu Title " },
{ &MenuItemList },
{ 2 },
};
void main( void )
{
printf("hello world");
}

static boolean fn_a( u8 token )
{
printf("fn_a called The token is %c",token);

return true;
}

static boolean fn_b( u8 token )
{
printf("fn_b called The token is %c",token);

return true;
}
Nov 14 '05 #1
9 6557


Ben Midgley wrote:
Please have a look at the code below

My problem is the error message "Nonportable pointer conversion", so far as
I can tell there is no pointer conversion occuring here so I am assuming it
is something implicit. The error is associated with the assignment {
&MenuItemList }, when delcaring the mit_ZoneSelectMenu structure.

I am using borland bcc32 the command line compiler which seems pretty good,
I just dont understand this issue.

[...]

typedef struct {
u8 string_a[_LEN_A_];
MenuItemT * pItemList;
This element has the type "pointer to MenuItemT."
u8 ItemCount;
} MenuT;

static boolean fn_a( u8 token );
static boolean fn_b( u8 token );

static volatile MenuItemT MenuItemList[] = {
/* "Item Name ", Item Handler Function */
{ "Item A" , &fn_a }, // Zone A
{ "Item B" , &fn_b }, // Zone B
{ NULL , NULL }
};

static volatile MenuT mit_ZoneSelectMenu[] = {
{ "Menu Title " },
{ &MenuItemList },


This initializer has the type "pointer to array
of MenuItemT," which is not the type of the element it
initializes. Drop the `&', and read Question 6.12 in
the comp.lang.c Frequently Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html

(Read Questions 6.12 and 6.8 as well -- oh, what the
heck: read all of Section 6; it's good for you.)

--
Er*********@sun.com

Nov 14 '05 #2

"Ben Midgley" <be********@tiscali.co.uk> wrote in message
news:41********@mk-nntp-2.news.uk.tiscali.com...
Please have a look at the code below

My problem is the error message "Nonportable pointer conversion", so far as I can tell there is no pointer conversion occuring here so I am assuming it is something implicit. The error is associated with the assignment {
&MenuItemList }, when delcaring the mit_ZoneSelectMenu structure.

I am using borland bcc32 the command line compiler which seems pretty good, I just dont understand this issue.
I point out your problem with this issue below,
but first, some others (some appear more than
once, I'll only point out the first occurrence
of each):

#include <stdio>
There is no standard header <stdio> in C. Perhaps
you meant <stdio.h>

#define _LEN_A_ 16 // this is minimum
Global names beginning with an underscore are reserved to the
implementation

typedef struct {
u8 ItemName[(_LEN_A_ - 1)];
Standard C has no such type as 'u8'.
boolean (*ItemHandler)( u8 Token );
Standard C has no such type as 'boolean'.
} MenuItemT;

typedef struct {
u8 string_a[_LEN_A_];
MenuItemT * pItemList;
u8 ItemCount;
} MenuT;

static boolean fn_a( u8 token );
static boolean fn_b( u8 token );

static volatile MenuItemT MenuItemList[] = {
/* "Item Name ", Item Handler Function */
{ "Item A" , &fn_a }, // Zone A
{ "Item B" , &fn_b }, // Zone B
{ NULL , NULL }
There's no declaration of 'NULL' in scope. The C
header which declares it is <stdlib.h>
};

static volatile MenuT mit_ZoneSelectMenu[] = {
{ "Menu Title " },
{ &MenuItemList },
OK here we go:

The name of an array in this context has type
'pointer to element type', in this case 'pointer
to MenuItemT' ('MenuItemT *').

The expression '&MenuItemList' has type 'pointer to
array of four MenuItemT' ( 'MenuItemT(*)[4]' ).
This is not the same as above.

I think you want for your second item:

MenuItemList

not

&MenuItemList
{ 2 },
};
void main( void )
'main()' is required to have return type 'int'.
{
printf("hello world");
No prototype for 'printf()' in scope. THe C header
which declares it is <stdio.h>

You should also terminate your output with a newline
character ('\n') or you're not guranteed the output
will appear.
Since 'main()' returns an 'int', return one:

return 0;
}

static boolean fn_a( u8 token )
{
printf("fn_a called The token is %c",token);

return true;
C has no keyword 'true', and you've not defined any
identifier with that name.
}

static boolean fn_b( u8 token )
{
printf("fn_b called The token is %c",token);

return true;
}


Perhaps you're using some nonstandard bastard version
of C. The above is far from ISO standard C, the topic
here.

-Mike

Nov 14 '05 #3

"Ben Midgley" <be********@tiscali.co.uk> wrote in message
news:41********@mk-nntp-2.news.uk.tiscali.com...
I am still getting that error.

Thanks for all the pointers, it is standard C I am using however I forgot to include some details held in an included header file which may help clear up a number of the points you raise. Sorry it was dumb of me not to spot that
they were missing. All perfectly valid though, I did miss the main return
type (I am used to embedded apps) and the use of underscore in defines was
news to me but I will keep it in mind in the future.

Here is the revised version which includes the below change. I just can't
shift the error message.

{ MenuItemList }, // changed from &MenuItemList, but also tried
&MenuItemList[0]
You also have a 'number of initializers' problem with
your array of structs, which I missed before.

More below.

Thanks for your help

Ben

// -- Start Here

#include <stdio.h>

#define LEN_A_ 16 // this is minimum

typedef unsigned char u8;
typedef signed char s8;

typedef unsigned short u16;
typedef signed short s16;

typedef unsigned long u32;
typedef signed long s32;

typedef float f32;
typedef double f64;

typedef unsigned char boolean;

#define true 1
#define false 0

typedef unsigned long AddressT;

#define NULL 0
DON'T DO THIS!!! The name "NULL" is defined by the library,
you're not allowed to define it yourself. <stdio.h> (and a
few other headers) already defines NULL for you.
typedef struct {
u8 ItemName[(LEN_A_ - 1)];
boolean (*ItemHandler)( u8 Token );
} MenuItemT;

typedef struct {
u8 string_a[LEN_A_];
MenuItemT * pItemList;
u8 ItemCount;
} MenuT;

static boolean fn_a( u8 token );
static boolean fn_b( u8 token );

static volatile MenuItemT MenuItemList[] = {
I'm not sure you understand the meanings of
'static' and 'volatile'. (Note that 'static'
has different meanings depending upon context)

I've created a compilable verson of your code
below, and removed the cases where specifying
'static' is redundant. I've left in the 'volatile',
(and added it in one place where it's needed if you
continue to use it) but I seriously doubt you need it
at all.

Corrected code at the end of this message.
/* "Item Name ", Item Handler Function */
{ "Item A" , &fn_a }, // Zone A
{ "Item B" , &fn_b }, // Zone B
{ NULL , NULL }
};

static volatile MenuT mit_ZoneSelectMenu[] = {
{ "Menu Title " },
{ MenuItemList }, // changed from &MenuItemList, but also tried
&MenuItemList[0]
{ 2 },
};

int main( void )
{
printf("hello world");

return 0;
}

static boolean fn_a( u8 token )
{
printf("fn_a called The token is %c",token);

return true;
}

static boolean fn_b( u8 token )
{
printf("fn_b called The token is %c",token);

return true;
}

The following will compile. Compare it very carefully
with yours, I've made many changes, some rather subtle.

Note that this code is compilable, but I did not try to
run it. It may or may not do exactly what you intend.
#include <stdio.h>

#define LEN_A_ 16 // this is minimum

typedef unsigned char u8;
typedef signed char s8;

typedef unsigned short u16;
typedef signed short s16;

typedef unsigned long u32;
typedef signed long s32;

typedef float f32;
typedef double f64;

typedef unsigned char boolean;

#define true 1
#define false 0

typedef unsigned long AddressT;

typedef struct {
u8 ItemName[LEN_A_ - 1];
boolean (*ItemHandler)(u8 Token);
} MenuItemT;

typedef struct {
u8 string_a[LEN_A_];
volatile MenuItemT * pItemList;
u8 ItemCount;
} MenuT;

static boolean fn_a( u8 token );
static boolean fn_b( u8 token );

volatile MenuItemT MenuItemList[] = {
/* "Item Name", Item Handler Function */
{ "Item A", fn_a}, // Zone A
{ "Item B", fn_b}, // Zone B
{ "", NULL}
};

volatile MenuT mit_ZoneSelectMenu[] = {
{ "Menu Title ", MenuItemList, 2},
};

int main(void)
{
printf("hello world\n");
return 0;
}

static boolean fn_a(u8 token)
{
printf("fn_a called The token is %c\n", token);
return true;
}

static boolean fn_b(u8 token)
{
printf("fn_b called The token is %c\n",token);
return true;
}

-Mike
Nov 14 '05 #4
Thanks mike, thats seen it - overzelous ( ..read wrong ) use of parenthesis
in the intitialiser right ?

There is no intention for this code, its a sample which reproduces an error
on a much more convaluted peice of code which I can now compile and now
works correctly (cheers). There was no point posting the whole thing.... no
one would have read 12,000 lines, right ? .

My use of static in all the instances below is just to limit scope. My use
of volatile - habit from working to misra, but it does no harm ....other
than maybe cost a little performace on a missed optimisation.

Thanks a million,

Ben

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:7K****************@newsread1.news.pas.earthli nk.net...

"Ben Midgley" <be********@tiscali.co.uk> wrote in message
news:41********@mk-nntp-2.news.uk.tiscali.com...
I am still getting that error.

Thanks for all the pointers, it is standard C I am using however I forgot
to
include some details held in an included header file which may help
clear up
a number of the points you raise. Sorry it was dumb of me not to spot

that they were missing. All perfectly valid though, I did miss the main return type (I am used to embedded apps) and the use of underscore in defines was news to me but I will keep it in mind in the future.

Here is the revised version which includes the below change. I just can't shift the error message.

{ MenuItemList }, // changed from &MenuItemList, but also tried &MenuItemList[0]


You also have a 'number of initializers' problem with
your array of structs, which I missed before.

More below.

Thanks for your help

Ben

// -- Start Here

#include <stdio.h>

#define LEN_A_ 16 // this is minimum

typedef unsigned char u8;
typedef signed char s8;

typedef unsigned short u16;
typedef signed short s16;

typedef unsigned long u32;
typedef signed long s32;

typedef float f32;
typedef double f64;

typedef unsigned char boolean;

#define true 1
#define false 0

typedef unsigned long AddressT;

#define NULL 0


DON'T DO THIS!!! The name "NULL" is defined by the library,
you're not allowed to define it yourself. <stdio.h> (and a
few other headers) already defines NULL for you.
typedef struct {
u8 ItemName[(LEN_A_ - 1)];
boolean (*ItemHandler)( u8 Token );
} MenuItemT;

typedef struct {
u8 string_a[LEN_A_];
MenuItemT * pItemList;
u8 ItemCount;
} MenuT;

static boolean fn_a( u8 token );
static boolean fn_b( u8 token );

static volatile MenuItemT MenuItemList[] = {


I'm not sure you understand the meanings of
'static' and 'volatile'. (Note that 'static'
has different meanings depending upon context)

I've created a compilable verson of your code
below, and removed the cases where specifying
'static' is redundant. I've left in the 'volatile',
(and added it in one place where it's needed if you
continue to use it) but I seriously doubt you need it
at all.

Corrected code at the end of this message.
/* "Item Name ", Item Handler Function */
{ "Item A" , &fn_a }, // Zone A
{ "Item B" , &fn_b }, // Zone B
{ NULL , NULL }
};

static volatile MenuT mit_ZoneSelectMenu[] = {
{ "Menu Title " },
{ MenuItemList }, // changed from &MenuItemList, but also tried &MenuItemList[0]
{ 2 },
};

int main( void )
{
printf("hello world");

return 0;
}

static boolean fn_a( u8 token )
{
printf("fn_a called The token is %c",token);

return true;
}

static boolean fn_b( u8 token )
{
printf("fn_b called The token is %c",token);

return true;
}

The following will compile. Compare it very carefully
with yours, I've made many changes, some rather subtle.

Note that this code is compilable, but I did not try to
run it. It may or may not do exactly what you intend.
#include <stdio.h>

#define LEN_A_ 16 // this is minimum

typedef unsigned char u8;
typedef signed char s8;

typedef unsigned short u16;
typedef signed short s16;

typedef unsigned long u32;
typedef signed long s32;

typedef float f32;
typedef double f64;

typedef unsigned char boolean;

#define true 1
#define false 0

typedef unsigned long AddressT;

typedef struct {
u8 ItemName[LEN_A_ - 1];
boolean (*ItemHandler)(u8 Token);
} MenuItemT;

typedef struct {
u8 string_a[LEN_A_];
volatile MenuItemT * pItemList;
u8 ItemCount;
} MenuT;

static boolean fn_a( u8 token );
static boolean fn_b( u8 token );

volatile MenuItemT MenuItemList[] = {
/* "Item Name", Item Handler Function */
{ "Item A", fn_a}, // Zone A
{ "Item B", fn_b}, // Zone B
{ "", NULL}
};

volatile MenuT mit_ZoneSelectMenu[] = {
{ "Menu Title ", MenuItemList, 2},
};

int main(void)
{
printf("hello world\n");
return 0;
}

static boolean fn_a(u8 token)
{
printf("fn_a called The token is %c\n", token);
return true;
}

static boolean fn_b(u8 token)
{
printf("fn_b called The token is %c\n",token);
return true;
}

-Mike

Nov 14 '05 #5
"Ben Midgley" <be********@tiscali.co.uk> writes:
Thanks mike, thats seen it - overzelous ( ..read wrong ) use of
parenthesis in the intitialiser right ?
Minor terminology nitpick:
() are usually called 'parentheses' (just one of them would be 'a
parenthesis')
{} are usually called 'braces' or 'curly brackets'.

But yes, arrays of derived types care very much about how many levels
of braces are wrapped around their initializers.
There is no intention for this code, its a sample which reproduces
an error on a much more convaluted peice of code which I can now
compile and now works correctly (cheers). There was no point posting
the whole thing.... no one would have read 12,000 lines, right ? .
If only all c.l.c posters would be as considerate. Another thing you
might try in future: don't top-post.
My use of volatile - habit from working to misra,
The only places 'volatile' can help, as far as I can see, are if

- the object designates a memory-mapped device or something which
acts like one, or

- the object can be read or written asynchronously by some other
entity (often: interrupt service routines).

Are there any uses for 'volatile' beyond these two?

BTW, that's the second time in the last couple months I've seen
someone quote MISRA as justification for questionable coding. Yours
is less severe - as you say:
but it does no harm ....other
than maybe cost a little performace on a missed optimisation.


The other person (a customer) wanted a way to convert an integer to a
pointer without casting an integer to a pointer (which is the method
one should use if one's compiler defines its results, surely?), as
MISRA says that's verboten. Apparently MISRA has no such objection to
inline assembly code that does exactly the same thing. I'm not sure
how this was conducive to Software Reliability.

mlp
Nov 14 '05 #6
Mark L Pappin wrote:
[...]
The only places 'volatile' can help, as far as I can see, are if

- the object designates a memory-mapped device or something which
acts like one, or

- the object can be read or written asynchronously by some other
entity (often: interrupt service routines).

Are there any uses for 'volatile' beyond these two?


Yes: see the description of setjmp().

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 14 '05 #7
Ben Midgley wrote:

[I have corrected a typo,included a typedef, and formatted]

#include <stdio.h>

#define _LEN_A_ 16 // this is minimum
typedef unsigned char u8, boolean;

typedef struct {
u8 ItemName [_LEN_A_ - 1];
boolean (*ItemHandler)( u8 Token );
} MenuItemT;

typedef struct {
u8 string_a [_LEN_A_];
MenuItemT * pItemList;
u8 ItemCount;
} MenuT;

static boolean fn_a( u8 token );
static boolean fn_b( u8 token );

static volatile MenuItemT MenuItemList[] = {
{ "Item A" , &fn_a }, // Zone A
{ "Item B" , &fn_b }, // Zone B
{ NULL , NULL }
};
NULL may be defined as (void *)0, which is not a
valid initializer for an array of chars. You should
either use 0, or "".

Also, I'm not entirely sure that (void *)0 is a valid
initializer for a function pointer (but it probably is).
};

static volatile MenuT mit_ZoneSelectMenu[] = {
{ "Menu Title " },
That was the initializer for mit_ZoneSelectMenu[0]
{ &MenuItemList },
That was the initializer for mit_ZoneSelectMenu[1].
&MenuListItem can't be converted to a char array.
{ 2 },
That was the initializer for mit_ZoneSelectMenu[2].
2 can't be converted to a char array.
};
You had too many braces, I think you meant to write:

static volatile MenuT mit_ZoneSelectMenu[] = {
{ "Menu Title ", &MenuItemList, 2 }
};

Now the problem is that mit_ZoneSelectMenu[0].pItemList
has type (MenuItemT *), but &MenuItemList has type
(MenuItemT volatile (*) [3]). You need to drop the
ampersand, and modify the definition of MenuT
to have: MenuItemT volatile *pItemList; void main( void )


int main(void), if you want to be portable.

Nov 14 '05 #8
On Mon, 17 Jan 2005 13:23:14 -0800, Old Wolf wrote:

....
Also, I'm not entirely sure that (void *)0 is a valid
initializer for a function pointer (but it probably is).


Normally you cannot convert implicitly between void * and function pointer
types, but any null pointer constant can be converted implicitly to any
pointer type. So (void *)0 is a valid initialiser for a function pointer
where, for example, (void *)(void *)0 isn't.

Lawrence
Nov 14 '05 #9
On Fri, 14 Jan 2005 22:33:52 GMT, "Mike Wahler"
<mk******@mkwahler.net> wrote:
<snip much good stuff>just two nits:
"Ben Midgley" <be********@tiscali.co.uk> wrote in message
news:41********@mk-nntp-2.news.uk.tiscali.com...

<many good points snipped, just a few nits for the record>
#include <stdio>


There is no standard header <stdio> in C. Perhaps
you meant <stdio.h>

<snip>
{ NULL , NULL }


There's no declaration of 'NULL' in scope. The C
header which declares it is <stdlib.h>

And several others, including stdio.h, which you correctly diagnosed
he meant to #include and the OP's code downthread confirms.

<snip>
return true;


C has no keyword 'true', and you've not defined any
identifier with that name.

C99 with <stdbool.h> does -- well, not a keyword, a predefined macro,
which is close enough -- but from the OP's code downthread he is in
fact using his own, as many people have done for a long time in C89.

- David.Thompson1 at worldnet.att.net
Nov 14 '05 #10

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

Similar topics

10
by: Chris Mantoulidis | last post by:
I see some really weird output from this program (compiled with GCC 3.3.2 under Linux). #include <iostream> using namespace std; int main() { char *s; s = "test1"; cout << "s = " << s << "...
12
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
10
by: FreeOperator | last post by:
Dear all, On Win2000 server with SP3, I am trying to access a SQL Server 7.0 database, "TestDB", from VB6 via a SQL Server ODBC system DSN using ADO 2.7. In SQL Server Enterprise Manager, there...
14
by: sachin_mzn | last post by:
Hi, Why I am not getting any run time error while accessing a freed memory in following code. This is printing h in std output. #include<stdio.h> main() { char* buffer = (char*)malloc(6);...
1
by: Ale K. | last post by:
i just reinstalled everything on my machine... i created a web project and when trying to run it i got the following.... What is it , how to fix it?? Thanks Error Server Error in '/Tester'...
2
by: teddybyte | last post by:
my script below is: #include "stdafx.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, ...
9
by: Trent | last post by:
Here is the error while using Visual Studio 2005 Error 1 error LNK2019: unresolved external symbol "void __cdecl print(int,int,int,int,int,int,int,int)" (?print@@YAXHHHHHHHH@Z) referenced in...
5
by: fimarn | last post by:
I am trying to get rid of compile time error that I am getting only in RHEL5 (not in RHEL4) apparently due to the changes in the stl_list.h file. The error that I am getting is coming from the...
63
by: Kapteyn's Star | last post by:
Hi newsgroup The program here given is refused by GCC with a error i cannot understand. It says rnd00.c: In function ‘main’: rnd00.c:26: error: expected expression before ‘]’ token ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.