Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This question is boggling my curiosity for the past day and a half.
I've put these two lines to test out explicit assignment of memory
addresses to pointers.

C#
char * ptr2;
ptr2=(char*)0xB0110000 ;


But every time compiler thinks i'm crazy:

1>------ Build started: Project: AFF_CPLUS_01, Configuration: Debug Win32 ------
1>  ChildsPlay.cpp
1>c:\users\grays4nd\documents\visual studio 2012\projects\aff_cplus_01\aff_cplus_01\childsplay.cpp(7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\grays4nd\documents\visual studio 2012\projects\aff_cplus_01\aff_cplus_01\childsplay.cpp(7): error C2040: 'ptr2' : 'int' differs in levels of indirection from 'char *'
1>c:\users\grays4nd\documents\visual studio 2012\projects\aff_cplus_01\aff_cplus_01\childsplay.cpp(7): error C2440: 'initializing' : cannot convert from 'char *' to 'int'
1>          There is no context in which this conversion is possible
1>c:\users\grays4nd\documents\visual studio 2012\projects\aff_cplus_01\aff_cplus_01\childsplay.cpp(14): error C2088: '<<' : illegal for class
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


When I try the same shenanigans inside of main() or other function, the compiler has no problem, only global assignment seems to present an issue. What gives?
Posted
Updated 18-Jan-13 19:42pm
v3

1 solution

The first line is a declaration, the second line is an assignment.

The compiler only expects declarations at file scope, so you get the "missing type specifier" error for the second line and the other errors follow on from that.

If you really want to set the pointer outside of the functions, do it all on one line:
C++
char *ptr2 = (char*)0xB0110000;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900