New child language - (Function member address (structure))

Pages: 1... 1415161718... 20
Yes, I'm sure, the compiler says so, but now I have an another solution : Using sprintf to format the pointer value, and finally strtol to convert string value to an unsigned value. Maybe the problem is "different compilers" :)

EDIT : Better solution I may use union structure... -> And the problem has been completely solved :)

Now I'm trying to make this :
 
char chr = strcpy(string, "abcde")[3];


Similar expression :

1
2
strcpy(string, "abcde");
char chr = string[3];


That's a more complex expression.

STRCPY returns char*, so also you may place an element request to access ith array item. It's pretty complex because the main pointer is void*, so I have no idea how to dereference an array and access exactly a specific element with position in different ways (char short etc)...

Any idea?
Last edited on
Are we also going to explain you how if's, for's and while's work? Have you ever practiced on simpler tasks? You don't even know how to cast a pointer.
Do you think we should tell JM about reinterpret_cast?
Last edited on
Whatever, but how come she can't get a simple C-style cast to work?
That's about the compiler itself, not me. :)
I've just switched to Dev Orwell and it is working now, thanks anyways.

EDIT : But honestly I dislike the Dev C ++ workspace. As L B said before, using reinterpret_cast is better... :D

But now no need to try to solve this problem anymore...I've alreadly had a pointer union structure..
Last edited on
You know, you can use VC++ and hate Microsoft at the same time...

Protip: If you want to use the 2012 version, the "Desktop" edition is the one that doesn't require Windows 8.
Quick, I completed the pointer returning value.

Now my interpreter is able to handle :
 
strcat(strcpy(string, "abc"), "def"));
lol the post count for this thread is insane i saw this when it first started and yall were just killing JM for being stupid and stuff lol i say good job JM for not loseing hope no matter what
The thread didn't just grow up with "stop the thread"-requests. It also contains questions, answers, and status report (of which we aren't caring as we don't even use that program actually - no links to it (I'm not blaming huh))
Oh, I'm now trying to clean up the interpreter code...
Very tired, the code is terribly long :(

About vector, I added a function which returns last element immediately if a new item is pushed.

1
2
3
4
5
6
7
	void push_back(const _Ty& _X)
		{insert(end(), _X); }
	reference back()
		{return (*(end() - 1));}

	inline reference push_back_and_access(const _Ty& _X)
		{insert(end(), _X);return (*(end() - 1));}


EDIT : Now I've just figured out "What is the difference between the operator (;) and (,) ?" :)

1
2
3
4
int number = 0;

if(number == 0)
number = 1, number *= 5, number = 100;


1
2
3
4
int number = 0;

if(number == 0)
{number = 1;number *= 5; number = 100;}


And, I was very confused...Am I stupid???
Last edited on
In that context there is no difference between those codes, but in the following case...
1
2
3
4
int Function()
{
    return 0, 3, 5;
}

5 will be returned as it's the rightmost value.
Yeah, TY I didn't know that... :)

That's about conditional expression, IF-WHILE-FOR, but currently I'm not going to implement this now...
Can anyone explain the FOR expression? In my opinion it's pretty complex (in short : crazy). Actually I don't fully understand it. Let me know how actually it looks like. :)
Last edited on
1
2
3
4
for(a; b; c)
{
    d;
}

a: code to run before the loop starts
b: code that could go inside an if(), the loop keeps running as long as it is true
c: code to run after each iteration of the loop
d: code to run each iteration of the loop

Example:
1
2
3
4
5
6
7
8
9
10
for(unsigned i = 0; i < 10; ++i)
{
    std::cout << i << std::endl;
}
0
1
2
3
4
5
6
7
8
9


Here's another example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
typedef std::vector<int> MyVec_t;
MyVec_t MyIntVec;

MyIntVec.push_back(7);
MyIntVec.push_back(2);
MyIntVec.push_back(4);
MyIntVec.push_back(64);
MyIntVec.push_back(8);
MyIntVec.push_back(-999);
MyIntVec.push_back(55);

for(MyVec_t::iterator it = MyIntVec.begin(); it != MyIntVec.end(); ++it)
{
    std::cout << *it << std::endl;
}
7
2
4
64
8
-999
55


All parts of the for loop are optional.

This is valid code, it is an infinite loop:

for(;;);

Identical to while(true);



http://www.cplusplus.com/doc/tutorial/control/#for
Last edited on
How are you writeing an interpreter and not know how to do the for statement??? thats like the 3rd chapter in every begineer c++ book
1
2
for(int a = 0; a < 5; a++)
{ DoIt(); }
translates to
1
2
3
4
5
6
7
8
{
    int a = 0;
    while( a < 5 )
    {
        DoIt();
        a++;
    }
}
Wow, thanks for your explanation. Now I have confidence enough to start implementing this now!

Woohoo!!!! Finally function pointer returning value has been successfully handled!!!!!

As I mentioned above, the simplest code (Accessing an unknown variable) :

1
2
3
4
5
6
7
8
char string[100];
int pos;

printf("Input string position : ");scanf("%d",&pos);

int result = strcpy(string, "abcdefghiklmo")[pos];

printf("string[%d] = %d (%c)", pos, string[pos], string[pos]);


Also you now can freely perform all operations on a function pointer as a regular variable. (full access)
Some examples :
1
2
3
4
5
6
7
strcpy(string, "abcdefghiklmo")[pos]++;

strcpy(string, "abcdefghiklmo")[pos] += 2;

printf("Input string[%d] : ", pos); 
scanf("%d", &strcpy(string, "abcdefghiklmo")[pos]);


IMPORTANT NOTE : The parser doesn't know the size of the function pointer array. So, if you access an invalid element, the program will collapse!!!

Now I'm going to make pointer variable definition. I've just discovered :
1
2
3
4
5
6
7
8
int *a = new int();
*a = 10;
printf("*a value : %d\n",*a);
printf("a[0] value : %d\n",a[0]);

a[0] += 10;
printf("*a value : %d\n",*a);
printf("a[0] value : %d\n",a[0]);


:D:D
Last edited on
If you are 55.69 % done, we can expect atleast 30 pages of this D: Just gotta get used to it :P
The first debug version is about to release when it reaches exactly 60 %.

Second release : 64.00%
Third release : 70.00%
Forth release : 74.00%
Last release : 80.00%

EDIT : Hey guys how to make template variable definition? And, is this possible? :)
Last edited on
How do you know how far into the project you are? I mean, an estimate I could understand, but you seem to believe that you know it exactly, to four significant figures, which seems like bull to me. Can you post your entire code somewhere? I want to see this thing even if it doesn't actually work, because right now, all you've posted is code snippets that don't seem like part of an interpreter, some that don't even compile, and some that seem to show that you don't have a clue how even the most basic constructs of the language you're using work (let alone the language you're supposedly interpreting). I'm at least 55.69% sure that you haven't actually written an interpreter at all, and I'm more than 55.69% sure you'll just ignore this comment or deflect it by saying "I'm not going to release it until I'm 60.00% done" or "It's too much code to post" or "You won't like it" or some other crap. And then, if and when you "reach" 60.00%, you'll just extend it again: "I'm not going to release it until it's 61.81% actually".
Last edited on
Im just about ready to ignore this whole thing
Pages: 1... 1415161718... 20