When I try to compile the following code I receive an error: "Type error in argument 1 to 'allocate'; found 'char * *', expected 'char *" at the line indicated (<<<<<). Explanations would be appreciated.
#include <stdio.h>
#include <string.h>
void allocate(char *dt);
int main(void)
{
char *data[3];
allocate(data); <<<<<
retu...
Hello,
I tried to make my code as simple as possible,but I failed at it.
This is my code:
class function TWS.WinsockSend(s:integer;buffer:pointer;size:word):boolean;
begin
dwError := Send(s,buffer,size,0);
// Debug
if(dwError = SOCKET_ERROR) then
begin
dwError := WSAGetLastError;
CloseSocket(s);
WSACleanup;
case ...
What is difference between %d and %u when printing pointer addresses?
For example:
int a=5;
// check the memory address
printf("memory add=%d\n", &a); // prints "memory add=-12"
printf("memory add=%u\n", &a); // prints "memory add=65456"
Please define.
...
I have written a program in which in the main function I declare an array of pointers and then I call a function which splits a given sentence and then want to assign it to the array of pointers in main(). I am unable to do. Can you please check the code pasted below:
int main(void)
{
char *data[3];
allocate(data);
...
I just made a Swap routine in C# like this:
static void Swap(ref int x, ref int y)
{
int temp = x;
x = y;
y = temp;
}
It does the same thing that this C++ code does:
void swap(int *d1, int *d2)
{
int temp=*d1;
*d1=*d2;
*d2=temp;
}
So are the ref and out keywords like pointers for C# without using unsafe code...
In Delphi:
How do I get the address (0x2384293) a pointer points to?
var iValue := Integer;
iptrValue := PInteger;
implementation
procedure TForm1.Button1Click(Sender: TObject);
begin
iptrValue := @iValue;
iValue := 32342;
//Should return the same value:
Edit1.Text := GetAddressOf(iptrValue);
Edit2.Text := GetAddressOf(...
One of the thing that has been confusing for me while learning C++ (and Direct3D, but that some time ago) is when you should use a pointer member in a class. For example, I can use a non-pointer declaration:
private:
SomeClass instance_;
Or I could use a pointer declaration
private:
Someclass * instance_
And then use new() o...
Learning as always, was going along quite nicely, until I realized I had no idea what the differences meant between these.
@class Player;
@class Map;
@interface View : NSView
{
Player* player_;
Map* currentMap_;
NSMutableArray *worldArray;
NSMutableArray *itemArray;
float cellHeight_;
}
@end
Never mind, turns out...
What I mean is: Imagine we have a 8 byte variable that has a high value and low value. I can make one pointer point to the upper 4 bytes and other point to the lower 4 bytes, and set/retrieve their values without problems. Now, is there a way to get/set values for anything smaller than a byte? If instead of dividing it in two 4 bytes "va...
Say we have opened a text file. Is it possible to define a pointer to a character in the file?
If it is - will the following characters in the file appear in memory in the same order they appear in the file?
The reason I ask:
I need to process a text file. I read one line at a time and there are certain strings I want to keep. The buffe...
Hello all,
I'm trying to run the following code(in gcc 4.3 on fedora 11 i586 ):
#include
#include
#include
struct s_smallstruct{
int smallstruct;
};
struct s_test2{
char * test2;
struct s_smallstruct* smallstruct;
};
struc...
var Buffer: TMemoryStream
The code:
Move((PByte(Buffer.Memory)+Buffer.Position)^, Buffer.Memory^, Buffer.Size - Buffer.Position);
Unfortunately this is not possible: Operator is not applicable to this type of operand.
So how can I get the starting point of a MemoryBuffer?
...
I wrote up this code after reading item 11 of Effective C++ ( Third Edition ).
#include <iostream>
using namespace std;
#define MAX_COLORS 20
class Widget
{
public:
Widget ( int seed );
~Widget ( );
Widget& operator=( const Widget& rhs );
void ToString ( );
private:
Widget& SelfAssignmentUnsafe ( const Widget& rh...
I have stumbled accross a strange problem in which I cannot understand. I am not an expert at C/C++ so bear with me. I have an NPC class, which derives from a Player class, which derives from a Sprite class. The sprite class contains a setupAnimation function, which allocates an array of floats containing coordinates on the texture, each...
I have the following code:
$data['x'] = $this->x->getResults();
$data['y'] = $data['x'];
//some code here to modify $data['y']
//this causes (undesirably) $data['x] to be modified as well
I guess since all the elements of $data are themselves references, modifying $data['y'] also modifies $data['x']..which is NOT what I want. I w...
In my embedded c program I have a struct:
struct var{
unsigned long value;
unsigned long length;
+ More
}
An array of these structs is used to hold variables. Most of the variables stored are simply stored in 'value' and so the length is set to 1.
However, some of these variables are arrays and Im trying to store the star...
If I declare
PSomeStruct = ^TSomeStruct;
TSomeStruct = record
s1 : string;
end;
and I run the following code:
var
p: PSomeStruct;
begin
new(p);
p^.s1:= 'something bla bla bla';
dispose(p);
the FastMM 4 memory manager reports that there was a memory leak (type: string, data dump: "something bla bla bla"). However, if I ...
I'd like to save a struct in a file.
I'd like to realize a function which makes this work.
I tried this code but it didn't work.
struct utilisateur // enregestrement pour sauvegarder les details de l utilisateur
{
char nom[20];
char prenom[20];
int place;
char depart[20];
char arrive[20];
char sexe;
int nwagon;
};
struct uti...
I think I've read somewhere that it is illegal to take the address of an enum value in C (enum values not being lvalues; however, I can't find any information on this now). Is that correct and, if so, why?
Edit:
Here's an example that clarifies what I mean by "enum value" above. I mean taking the address of first_value below, not tak...
Hi!
Short form: Is it possible to create a stream from a pointer?
I have a pointer which points to file data I need to read. I used WriteBuffer() to transfer data from the pointer to a TFileStream, which works. But now I want to read it block wise to display a progress bar. So I need to read it step by step.
I have to options:
1) In...