gerard4143 371 Nearly a Posting Maven

Well let me start off by saying memset is the proper way to initialize an array but if you want to see AT & T inline asm then you really should check the many docs on the internet..Here's my very simple version..Note its for a 64 bit Intel/AMD system.

include <stdio.h>

#define SIZE 10
int test[SIZE];

int main()
{
	int i = 0;

	for (i = 0; i < SIZE; ++i)
		test[i] = i + 3;

	for (i = 0; i < SIZE; ++i)
		fprintf(stdout, "ans->%d\n", test[i]);

	__asm__
	(
		"pushq	%rdi\n\t"
		"pushq	%rax\n\t"

		"xorq	%rdi, %rdi\n\t"		

		"call	1f\n\t"
		"1:\n\t"
		"popq	%rax\n\t"
		"addq	$5, %rax\n\t"
		
		"cmpq	$9, %rdi\n\t"
		"je	2f\n\t"

		"movq	$0, test(, %rdi, 4)\n\t"

		"incq	%rdi\n\t"
		"jmp	*%rax\n\t"

		"2:\n\t"
		"popq	%rax\n\t"
		"popq	%rdi\n\t"
	);

	for (i = 0; i < SIZE; ++i)
		fprintf(stdout, "ans->%d\n", test[i]);
	return 0;
}

Output on my system

ans->3
ans->4
ans->5
ans->6
ans->7
ans->8
ans->9
ans->10
ans->11
ans->12
ans->0
ans->0
ans->0
ans->0
ans->0
ans->0
ans->0
ans->0
ans->0
ans->0

gerard4143 371 Nearly a Posting Maven

I don't know why people have such difficulties with pointers. A pointer is a variable, its just like an integer variable except the values are memory addresses and the language C allows dereferencing pointers to obtain the value that's pointed to. Simple right?

Now your question. If you perform these operations

int *pointer = 30000; store address 30000 into pointer
int *pointer2 = pointer; // store address 30000 into pointer2

then pointer and pointer2 are storing the same values.

You could ask if

int x = 3000;
int y = x;

is x equivalent to y? Yes x and y values are equivalent.

gerard4143 371 Nearly a Posting Maven

It could be 'appearing' to hang because the algorithm is very inefficient and its taking a long time to calculate the bigger perfect numbers. Let it run for a few hours.

gerard4143 371 Nearly a Posting Maven

Do mean inline asm?

gerard4143 371 Nearly a Posting Maven

Short answer: It is in the standard.
Medium answer: It is both in the standard AND a source of much confusion, because of the complexity of the issue.

Thanks for the prompt rely to one of my many C++ questions. Its good to know the standard will ensure consistent usage in this case..Again thank-you.

gerard4143 371 Nearly a Posting Maven

I have a question about function precedence. How does the compiler decide which function to call in quasi ambiguous situations? Is it laid out in the standard or is it implementation dependent?


If you look at the attached code you'll see I'm outputting the value contained by the myint object. Now I can remove the overloaded output operator and the program will appear the run exactly the same because it will use the conversion operator 'operator int()'. So how does the compiler choose? Is it vendor specific or is it decided by the standard? I tried googling but I keep getting operator precedence...So any thoughts on this?

#include <iostream>

class myint
{

public:

	myint(int val):itsvalue(val) {}

	operator int() { return itsvalue; }

	int getitsvalue() const { return itsvalue; }

private:

	int itsvalue;

};

//remove overloaded output operator and everything appears the same.
std::ostream& operator <<(std::ostream & out, const myint & m)
{
	return out << m.getitsvalue();
}

int main()
{
	myint me(47);

	std::cout << me << std::endl;
	return 0;
}
gerard4143 371 Nearly a Posting Maven

I was playing with this a while ago...quite a while ago so I can't guarantee that any of this code will work..

Here's the code that I used.

mywrap.c

#include <Python.h>

extern int intlimit(int);
extern int glblimit(int);
extern void* intbase(unsigned long);
extern void* glbbase(unsigned long);
extern unsigned long myfunc(void*);

PyObject *testex_myfunc(PyObject *self, PyObject *args)
{
	void* val;
	PyObject *MyObj;
	unsigned long ans;
		
	if (!PyArg_ParseTuple(args, "O", &MyObj))
	{
		return NULL;	
	}
	
	val = PyLong_AsVoidPtr(MyObj);	
	
	ans = myfunc(val);
		
	return Py_BuildValue("l", ans);
}


PyObject *testex_glbbase(PyObject *self, PyObject *args)
{
	void* ans;
	unsigned long val;
	
	if (!PyArg_ParseTuple(args, "l", &val))
	{
		return NULL;	
	}
	
	ans = PyLong_FromVoidPtr(glbbase(val));
	
	return Py_BuildValue("O", ans);
}

PyObject *testex_intbase(PyObject *self, PyObject *args)
{
	void* ans;
	unsigned long val;
	
	if (!PyArg_ParseTuple(args, "l", &val))
	{
		return NULL;	
	}
	
	ans = PyLong_FromVoidPtr(intbase(val));
	
	return Py_BuildValue("O", ans);
}


PyObject *testex_intlimit(PyObject *self, PyObject *args)
{
	int ans, val;
	
	if (!PyArg_ParseTuple(args, "i", &val))
	{
		return NULL;	
	}
	
	ans = intlimit(val);
	
	return Py_BuildValue("i", ans);
}

PyObject *testex_glblimit(PyObject *self, PyObject *args)
{
	int ans, val;
	
	if (!PyArg_ParseTuple(args, "i", &val))
	{
		return NULL;	
	}
	
	ans = glblimit(val);
	
	return Py_BuildValue("i", ans);
}


static PyMethodDef testexmethods[] = 
{
	{"intlimit", testex_intlimit, METH_VARARGS,"return interrupt table limit"},
	{"glblimit", testex_glblimit, METH_VARARGS,"return global table limit"},
	{"intbase", testex_intbase, METH_VARARGS,"return interrupt base address"},
	{"glbbase", testex_glbbase, METH_VARARGS,"return global base address"},
	{"myfunc",testex_myfunc,METH_VARARGS,"get pointer value"},
	{NULL,NULL},
};

void inittestex(void)//the name of the module is testex but this function must be called inittestex 
{
	Py_InitModule("testex", testexmethods);
}

test.c

int intlimit(int val)
{
	char ch[(sizeof(unsigned short) + sizeof(void*))];
	
	__asm__ __volatile__
	( …
gerard4143 371 Nearly a Posting Maven

No your data is safe. When you reassign pointer, its just gets the address of your string "weeeeeeeeeeeeeeeeeeeeeee".

"hi" - has one address value.
"weeeeeeeeeeeeeeeeeeeeeee" - is another address value.

gerard4143 371 Nearly a Posting Maven

It really depends on your C implementation but you can say that it's not proper or safe.

gerard4143 371 Nearly a Posting Maven

Here's what I would do in the for loop

pointer[0].health = some_value;
pointer[0].armor = some_value;
pointer[0].nextaddr = &pointer[1];

Instead of using the constants 0,1 for the array indexes, use variables that increment in the for loop. Also make sure you remember that the last node points to nothing(NULL).

gerard4143 371 Nearly a Posting Maven

Try changing your array to..

int test[2][2][2];

Try running this code below

#include <stdio.h>
#include <stdlib.h>

int test[1][1][1];
int test2[2][2][2];

int main()
{
	fprintf(stdout, "array elements->%lu\n", sizeof(test)/sizeof(int));
	fprintf(stdout, "array elements->%lu\n", sizeof(test2)/sizeof(int));
	return 0;
}
gerard4143 371 Nearly a Posting Maven

If you look at your code you'll see that nptr is NULL. Your trying to dereference NULL.

gerard4143 371 Nearly a Posting Maven

Try changing line 16 to

newNode->data = n->data;

gerard4143 371 Nearly a Posting Maven

Can you show us how your calling insertHead()?...Ooops, its line 16 of the posted code. Your assigning struct node *n to newNode->data. Is newNode->data an int?

gerard4143 371 Nearly a Posting Maven

You are correct. A reference is not actually an instance of a class. A reference is more like a pointer, but doesn't have all the extra syntax. Thus, the reference can reach the end of its life, or go out of scope, without destroying the original object because the original object may not have reached the end of its life yet.

Thanks for the reply...One minute after I posted I thought of this situation

int main()
{
	myint me(123);
	myint &you = me;

	return 0;
}

which shows that the reference to an object mustn't call the destructor..I think I need some sleep.

gerard4143 371 Nearly a Posting Maven

Am I correct assuming that a reference to an object will not call the object's destructor when the reference goes out of scope? The code I attached supports my assumption but I'm not certain if its correct...Any comments?

#include <iostream>

class myint
{
	public:

		myint():itsvalue(0) {}
		myint(unsigned long val):itsvalue(val) { std::cout << "constructing->" << itsvalue << std::endl; }

		~myint() { std::cout << "destroying->" << itsvalue << std::endl; }

		std::ostream& print(std::ostream & out) const { return out << itsvalue; }

	private:

		unsigned long itsvalue;
	
};

std::ostream& operator <<(std::ostream & out, const myint & m)
{
	return m.print(out);
}

myint& myfunc(void)
{
	myint *ans = new myint(123);
	return *ans;
}

void myfunc2(void)
{
	myint & myr = myfunc();

	std::cout << myr << std::endl;
	//the reference myr doesn't call the destructor ~myint() when it goes out of scope
}

int main()
{
	myfunc2();
	return 0;
}
gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

I think you want a conversion operator..I think? Try looking up this link and see if its what your after..

http://www.devx.com/tips/Tip/12459

gerard4143 371 Nearly a Posting Maven

You should be able to call the destructor which should call delete of the variable that points to the next node.

gerard4143 371 Nearly a Posting Maven

Try writing some simple programs and find out for yourself.

gerard4143 371 Nearly a Posting Maven

Wow, you really couldn't google this?

gerard4143 371 Nearly a Posting Maven

Line 7

int area = (p(p - a)(p - b)(p - c))/2;

should probably be

int area = (p * (p - a) * (p - b) * (p - c))/2;

also line 13 your calling

convert();

You haven't defined a function convert.

gerard4143 371 Nearly a Posting Maven

A quick inspection of the code reveals that your not resetting the variable judgeCounter back to zero.

A note on code indentation...Please use it.

#include <iostream>

using namespace std;

int main ()
{

	int numberOfCompetitors;
	float judgesScore;
	float finalScore = 0.0;
	int competitorCounter = 1;
	int judgeCounter = 1; 
	float lowestScore = 6.0; 
	float highestScore = 0.0;


	cout << "\n Welcome to the Diving Score program which \n determines the final score of each diver\n";
	cout << " =========================================\n\n";

	cout << "Please enter the number of competitors: "; 
	cin >> numberOfCompetitors; 

	while (competitorCounter <= numberOfCompetitors) 
	{
		while (judgeCounter <= 5)
		{
			cout << "\nEnter the score for judge " << judgeCounter << ": ";
			cin >> judgesScore;

    			if (judgesScore >= 0.0 && judgesScore <= 6.0)
			{
                		finalScore += judgesScore; 
                
    				if (judgesScore < lowestScore)
				{
      					lowestScore = judgesScore;
				} 
      
    				if (judgesScore > highestScore)
				{ 
				      highestScore = judgesScore;
				}       
                
				judgeCounter += 1; 
			}
			else 
			{
				cout << "You have entered an incorrect value.\nPlease enter a value between 0.0 and 6.0...\n\n";
			}
		}
			cout << "highestScore = " << highestScore;
			cout << "\nloweastScore = " << lowestScore <<endl;

		       finalScore = (finalScore - highestScore - lowestScore) / 3; 
		       cout << endl << "finalScore for Competitor " << competitorCounter << " is: " << finalScore <<endl;

		       competitorCounter += 1;
		       judgeCounter = 0;
	}

	return 0;
}
gerard4143 371 Nearly a Posting Maven

You could start by telling us what the problem is..

gerard4143 371 Nearly a Posting Maven

Warnings not errors and you should be getting them.

gerard4143 371 Nearly a Posting Maven

I think it's Ctrl-D on those systems, actually.

Ooops my bad.

gerard4143 371 Nearly a Posting Maven

Ctrl+z

gerard4143 371 Nearly a Posting Maven

Yeah, sure why not?

gerard4143 371 Nearly a Posting Maven

The easiest way around this problem is to create a function in C that's exactly the same as the asm function and then see how the C program calls that function...I would take an objdump of the C code and take it from there.

The next(and harder) approach is to handle the function call, in the C program, with inline asm, making sure you pass everything correctly.

gerard4143 371 Nearly a Posting Maven

You have to pass the memory location that contains the pointers to the cstrings. If you think about it, it makes sense.

Here's a big hint. If you were to define your function like below

void swap(char *a, char *b);

What would happen when you call it? It would create two temp variables char *a and char *b which would store the pointers to the cstrings...now when we swap them and the functions returns char *str1 and char *str2 remain unaffected. Why? because char *str1 and char *str2 have they're own copies of the cstring pointer values...

gerard4143 371 Nearly a Posting Maven

You define, on line 123

char line[50];

And then use fgets on line 139

fgets(line,20,file)

Why?

I tried compiling your program and received these two warnings

In function ‘count’:
111: warning: control reaches end of non-void function
In function ‘table’:
49: warning: control reaches end of non-void function

Both functions, table and count, expect return values of float.

gerard4143 371 Nearly a Posting Maven

hi,
thanks for the help but it's not the right answer!!there is a stack problem!!
we need to access to the stack etc but i don't know how

O.K. maybe you could tell us what the 'stack problem' is.

gerard4143 371 Nearly a Posting Maven

Oh, then just declare an extern variable like so

extern int x;

and then include your asm code into the project. I never used code blocks so I don't know the specifics.

gerard4143 371 Nearly a Posting Maven

This functionality exists as a language extension so it depends on which compiler your using...So which compiler are you using?

gerard4143 371 Nearly a Posting Maven

Finished by being caught and handled, or finished by being unhandled? In the former case, the destructor is properly called and the object ends after the final exception handler completes. In the latter case, abort is called, which is a hard terminate on the program.

I meant the former and thank-you for clearing that up

gerard4143 371 Nearly a Posting Maven

I have a simple question about objects and exception handling.

What happens to an object after its thrown? Does the implementation take of cleaning up that object or should I be aware of any situations that may require extra care...I've read this from - Inside The C++ Object Model by Stanley B. Lippman pg 261

"When an exception is thrown, the exception object is created and placed generally on some form of exception data stack"

This is great to know but I can't find any mention of what happens to that object after the exception is finished...Could someone please enlighten me...Thanks.

gerard4143 371 Nearly a Posting Maven

Because that's what the function does..Here's a quote from my help file

"int putchar(int c);
writes the character c, cast to an unsigned char, to stream"

gerard4143 371 Nearly a Posting Maven

When you enter a character from the console you hit return as well so you really enter two characters..e.g

Enter the character 'a' plus return yeilds

'a', '\n'

Instead of using putchar() try using

fprintf(stdout, "value->%d\n", t);
fprintf(stdout, "value->%d\n", x);

What values were displayed?

gerard4143 371 Nearly a Posting Maven

Well what's it supposed to do? Can you give us an example of how its failing?

Oh by the way, don't use fflush(stdin) its behavior is undefined.

gerard4143 371 Nearly a Posting Maven

Yes its possible, try googling fseek, ftell, fopen.

gerard4143 371 Nearly a Posting Maven

In the simplest terms...Don't do this, its wrong.

ch1= (char *)realloc(ch1,1);
ch1++;

gerard4143 371 Nearly a Posting Maven

I don't like that your realloc'ing ch1 and then incrementing the pointer ch1. To me this seems like a recipe for disaster

gerard4143 371 Nearly a Posting Maven

Then let me re-phrase my question, who is putting all these bugs on our computers and why, they make no money, so what do they get out of it. Are they Mafia, Smart guys having fun, or techies creating business, or what.

I know one thing they are vicious hateful people and they make sure no one enjoys a marvelous creation called the computer.

Those are the black hats and crackers...Why do they do it? To get a reputation, to become infamous.

gerard4143 371 Nearly a Posting Maven

Here's a good link on how to become a hacker...well how to become a traditional hacker

http://www.catb.org/~esr/faqs/hacker-howto.html

gerard4143 371 Nearly a Posting Maven

Inside The C++ Object Model by Stanley B. Lippman

I recommend this book for one reason even through its a very good book from cover to cover, it explains in simple terms why polymorphism, in C++, requires pointers or references to objects...If your interested check out page 29.

gerard4143 371 Nearly a Posting Maven

Try removing the () in

if ((textBox1->Text == ("")) &&

so that its is

if ((textBox1->Text == "") &&

Actually on further inspection, you have on line 3

(radioButton3->Checked = false)

it should be

(radioButton3->Checked == false)

gerard4143 371 Nearly a Posting Maven

Why? Because the posted code is full of errors.

gerard4143 371 Nearly a Posting Maven

I tried using a global integer array to pass the values to each thread...It seems to work.

#include <iostream>
#include <windows.h>
#include <cstdio>

#define NO_THREADS 4

int thread_a[NO_THREADS];

class Thread
{
    public:
    Thread();
    static void * EntryPoint(void*);
    int Start();
    int Run(int arg);
    void Execute(int);
    int Arg() const {return Arg_;}
    void Arg(int a){Arg_ = a;}
    private:
    int Arg_;
};

Thread::Thread() {}

void * Thread::EntryPoint(void * pthis)
{
    Thread * pt = (Thread*)pthis;
    pt->Run( pt->Arg() );
    return 0;
}

int Thread::Start()
{
    HANDLE h[4];

    for (int i = 0; i < 4; i++)
    {
        thread_a[i] = i + 1;
        h[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)EntryPoint, &thread_a[i], 0, NULL);
    }

    WaitForMultipleObjects(4, h, TRUE, INFINITE);

    return 0;
}

int Thread::Run(int arg)
{
    Execute( arg );
    return 0;
}

void Thread::Execute(int a)
{
    printf("%d\n", a);
}

int main()
{
    Thread pt;
    pt.Start();
    return 0;
}
gerard4143 371 Nearly a Posting Maven

After I include cstdio the program compiled and ran as expected..Actaully line 33 in your program might be incorrect. Your passing the address of dwArg to create thread which is changing as the loop iterates, this is probably what's causing the weird nummbers.

gerard4143 371 Nearly a Posting Maven

Check this out

Broken-down  time  is  stored  in  the structure tm which is defined in
       <time.h> as follows:

           struct tm {
               int tm_sec;         /* seconds */
               int tm_min;         /* minutes */
               int tm_hour;        /* hours */
               int tm_mday;        /* day of the month */
               int tm_mon;         /* month */
               int tm_year;        /* year */
               int tm_wday;        /* day of the week */
               int tm_yday;        /* day in the year */
               int tm_isdst;       /* daylight saving time */
           };

       The members of the tm structure are:

       tm_sec    The number of seconds after the minute, normally in the range
                 0 to 59, but can be up to 60 to allow for leap seconds.

       tm_min    The number of minutes after the hour, in the range 0 to 59.

       tm_hour   The number of hours past midnight, in the range 0 to 23.

       tm_mday   The day of the month, in the range 1 to 31.

       tm_mon    The number of months since January, in the range 0 to 11.

       tm_year   The number of years since 1900.

       tm_wday   The number of days since Sunday, in the range 0 to 6.

       tm_yday   The number of days since January 1, in the range 0 to 365.

       tm_isdst  A  flag  that  indicates  whether  daylight saving time is in
                 effect at the time described.  The value is positive if  day‐
                 light  saving time is in effect, zero if it is not, and nega‐
                 tive if the information is not available.

Or this web site which took me 30 secs to …