473,385 Members | 1,427 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,385 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 2282
"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: 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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.