473,405 Members | 2,141 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,405 software developers and data experts.

fixed

I have the following code in one of my programs;

ert= CO3;
int Code = SR(ert, 1024, 1024);

char[] UnsafeTempBuffer = new char[128];
fixed ( char* tBuffer= UnsafeTempBuffer)
{
Code = Siofunc(tBuffer, 128);
}
When I try to compile I receive the error, Pointer may only be used in an
unsafe context. Isn't that what I'm doing?
So what's wrong with it? The error is called for the line with fixed in
it.

Nov 16 '05 #1
3 2283
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
I have the following code in one of my programs;

ert= CO3;
int Code = SR(ert, 1024, 1024);

char[] UnsafeTempBuffer = new char[128];
fixed ( char* tBuffer= UnsafeTempBuffer)
{
Code = Siofunc(tBuffer, 128);
}
When I try to compile I receive the error, Pointer may only be used in an
unsafe context. Isn't that what I'm doing?
So what's wrong with it? The error is called for the line with fixed in
it.


You should tag the method that does the fixing, with the keyword 'unsafe',
as follows:

public unsafe void f()
{
// can use fixed expression
}

Or, You can make a certain scope unsafe by again using the 'unsafe' keyword,
as follows:

public void f()
{
// ... safe code
unsafe
{
// ... unsafe code here (eg fixed statements and use of pointers)
}
// ... safe code
}

Hope this helps,
---
Tom Tempelaere
Nov 16 '05 #2
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
I have the following code in one of my programs;

ert= CO3;
int Code = SR(ert, 1024, 1024);

char[] UnsafeTempBuffer = new char[128];
fixed ( char* tBuffer= UnsafeTempBuffer)
{
Code = Siofunc(tBuffer, 128);
}
When I try to compile I receive the error, Pointer may only be used in an
unsafe context. Isn't that what I'm doing?
So what's wrong with it? The error is called for the line with fixed in
it.


Dave,

You must also go the your project properties, and set the "Allow unsafe code
blocks" option to true.

Cheers,
---
Tom Tempelaere
Nov 16 '05 #3
Thanks, that solved my problem.

"TT (Tom Tempelaere)" wrote:
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
I have the following code in one of my programs;

ert= CO3;
int Code = SR(ert, 1024, 1024);

char[] UnsafeTempBuffer = new char[128];
fixed ( char* tBuffer= UnsafeTempBuffer)
{
Code = Siofunc(tBuffer, 128);
}
When I try to compile I receive the error, Pointer may only be used in an
unsafe context. Isn't that what I'm doing?
So what's wrong with it? The error is called for the line with fixed in
it.


You should tag the method that does the fixing, with the keyword 'unsafe',
as follows:

public unsafe void f()
{
// can use fixed expression
}

Or, You can make a certain scope unsafe by again using the 'unsafe' keyword,
as follows:

public void f()
{
// ... safe code
unsafe
{
// ... unsafe code here (eg fixed statements and use of pointers)
}
// ... safe code
}

Hope this helps,
---
Tom Tempelaere

Nov 16 '05 #4

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

Similar topics

26
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " ...
9
by: pout | last post by:
What are the purposes of fixed-point? When should it be used? I read: #define Int2Fixed(x) (((long)(short)x) << 16) and the fixed-point in 16.16 format. Does the 16 in the MACRO refer to...
9
by: pout | last post by:
What are the purposes of fixed-point? When should it be used? I read: #define Int2Fixed(x) (((long)(short)x) << 16) and the fixed-point in 16.16 format. Does the 16 in the MACRO refer to...
4
by: Otie | last post by:
Hello, I am using the MSFlexGrd Control in VB5. I have 1 fixed row and one fixed column. I am trying to do a sort when the user clicks a column in the FIXED ROW. But when I capture the row...
1
by: O.B. | last post by:
In the example below, I'm trying to convert a fixed byte array to a string. I get an error about needing to use "fixed" but I have no clue where to apply it. Help? using System; using...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.