gerard4143 371 Nearly a Posting Maven

C can be transfered to different machines because the standard library abstracts away may of these details...i.e. The language is the same but each machine gets its own standard library to handle these details. So when you transfer source code between machines and recompile the standard library makes sure everything lines up for that machine...

gerard4143 371 Nearly a Posting Maven

Give me money

gerard4143 371 Nearly a Posting Maven

1. why do you do this "After filling out this info, I am using memmove() to put all of the data into a char array and use send() to send the information. All of the sent data (except sendString) is converted to network byte ordering." just cast the structure to char* and send the structure.

2. You can't/shouldn't send a char pointer across a network, its has no meaning in the new address space. Instead just send the message as a character array...

gerard4143 371 Nearly a Posting Maven

This doesn't make any sense to me...Could you elaborate

gerard4143 371 Nearly a Posting Maven

choice is defined as "" maybe you should try defining it as an array of characters. Something like

choice:  db "                                    "
gerard4143 371 Nearly a Posting Maven

To set up stack 64KB in length for segment number
0x8000, you would load SP with 0000, it may sound strange
but when something is pushed on the stack 0000 will become
FFFE because PUSH decrements SP by -2, hence every byte
of the stack will be used.

mov ax, 0x8000
mov ss, ax
mov sp, 0x0

Yeah that is weird. I only guessed at that part because I couldn't find any doc's on initializing the stack pointer, but I knew the stack started high and worked its way down...Good bit of info. Thanks...

gerard4143 371 Nearly a Posting Maven

I updated my boot disk that I made some time ago...It now supports a function call and a stack. The functionality I added is from any information I could find on Google so I can noway guarantee that this is the correct way to do this, all I know is that its works on my old PII computer....

assem code

.code16

.section .data

.section .text
	.global _start
_start:
			movw	$0xb800, %ax
			movw	%ax, %es
			movw	$0x8000, %ax
			movw	%ax, %ss
			movw	$0xfffe, %sp



			call	tohere
		
loop1:
			jmp	loop1


tohere:
			movb	$0x47, %es:0
			movb	$0x1f, %es:1

			movb	$0x34, %es:2
			movb	$0x1f, %es:3

			movb	$0x31, %es:4
			movb	$0x1f, %es:5

			movb	$0x34, %es:6
			movb	$0x1f, %es:7

			movb	$0x33, %es:8
			movb	$0x1f, %es:9

			movb	$0x20, %es:10
			movb	$0x1f, %es:11	

			movb	$0x48, %es:12
			movb	$0x1f, %es:13	

			movb	$0x61, %es:14
			movb	$0x1f, %es:15	

			movb	$0x63, %es:16
			movb	$0x1f, %es:17

			movb	$0x6b, %es:18
			movb	$0x1f, %es:19

			movb	$0x65, %es:20
			movb	$0x1f, %es:21	

			movb	$0x72, %es:22
			movb	$0x1f, %es:23			

			movb	$0x20, %es:24
			movb	$0x1f, %es:25	

			movb	$0x46, %es:26
			movb	$0x1f, %es:27	

			movb	$0x6f, %es:28
			movb	$0x1f, %es:29

			movb	$0x72, %es:30
			movb	$0x1f, %es:31

			movb	$0x75, %es:32
			movb	$0x1f, %es:33	

			movb	$0x6d, %es:34
			movb	$0x1f, %es:35	

			movb	$0x73, %es:36
			movb	$0x1f, %es:37					

			movb	$0x20, %es:38
			movb	$0x1f, %es:39

			ret

These are the lines that I set up my stack. I move 0x8000 hex into the ss segment register and initialize the stack pointer to 0xfffe. Like I said I'm not sure if this is correct all I know …

gerard4143 371 Nearly a Posting Maven

I'm no expert programming with 16 bit Intel or boot floppies(only did it once out of curiosity) but here's a website that addresses your question

http://www.emu8086.com/assembly_language_tutorial_assembler_reference/asm_tutorial_09.html

gerard4143 371 Nearly a Posting Maven

This Question is not programming related but rather important for all compiler related programming languages especially the Language C.

what is portabily?

since my graduation i have been taught C is not 100 % portable language.

but i dint get any satisfactory answers for,not 100 % portable?
where its lagging and why can't we make it 100 % portable?

How a compiler generates the portable code for all the processors

Assembly language is considered as non portable language because the instruction are understandable only by the specific processor.

but how a compiler is able to generate code that is understandable by all the processors.

when i install a compiler i dont worry on what processor my system runs ( i only worry about OS, what OS does to compiler?)

again the OS may run on different processors.

but how a particular comipler is able to generate code that almost works on all processors with minor or few modifications.

i believe we can run Windows OS, Linix OS on Motorola as well as Intel or AMD or some other processors.

but how the same compiler is able to generate code for different processor.

thanks in advance.

A C compiler doesn't create code that's portable, it just creates an exe in the host machine language(well this isn't entirely true, gcc can cross compile). The source code that's created by the programmer can be portable, if it uses the standard libraries, because you can take this source(plus standard libraries) to another machine …

gerard4143 371 Nearly a Posting Maven

Please can anyone help me in the making of this program :

We have to Enter a string of capital letters like

WJKTYNHJHIJKLMNOPASC

THE LONGEST CONSECUTIVELY INCREASING STRING IS

HIJKLMNOP

.
.
.

Help me Please , Thanks !!!

You are not giving enough information..please elaborate

gerard4143 371 Nearly a Posting Maven

I almost forgot to tell you, if your using 64 bit linux assembly programming then most of the books and tuts out there are out dated...The ABI(application binary interface) for Linux 64 bit programs are different than the 32 bit ABI...Below is an excerpt from the Entry_64.S file from a 64 bit kernel source...Please note the order that registers are pasted data for a system call...You'll see I used this order in the 64 bit code above

%rax
%rdi
%rsi
%rdx
%r10
%r8
%r9
%r11

/*
 * System call entry. Upto 6 arguments in registers are supported.
 *
 * SYSCALL does not save anything on the stack and does not change the
 * stack pointer.
 */

/*
 * Register setup:
 * rax  system call number
 * rdi  arg0
 * rcx  return address for syscall/sysret, C arg3
 * rsi  arg1
 * rdx  arg2
 * r10  arg3 	(--> moved to rcx for C)
 * r8   arg4
 * r9   arg5
 * r11  eflags for syscall/sysret, temporary for C
 * r12-r15,rbp,rbx saved by C code, not touched.
 *
 * Interrupts are off on entry.
 * Only called from user space.
 *
 * XXX	if we had a free scratch register we could save the RSP into the stack frame
 *      and report it properly in ps. Unfortunately we haven't.
 *
 * When user can change the frames always force IRET. That is because
 * it deals with uncanonical addresses better. SYSRET has trouble
 * with them due to bugs in both AMD and Intel CPUs.
 */
gerard4143 371 Nearly a Posting Maven

Lets see what you have so far

gerard4143 371 Nearly a Posting Maven

Then you'll have to convert the hex/binary value(s) into the a ascii text representation before you write them to file

gerard4143 371 Nearly a Posting Maven

Try this code...I'm not sure if your running a 32 or 64 bit box...

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

void printit(char *chr)
{
	//64 bit
	__asm__ __volatile__
	(
	 	"movq	$1, %%rax\n\t"
		"movq	$1, %%rdi\n\t"	
		"movq	%0, %%rsi\n\t"
		"movq	$1, %%rdx\n\t"
		"syscall\n\t"
		:"=m"(chr)
	);
	//32 bit - Note untested
	//__asm__ __volatile__
	//(
	//	"movl	$4, %%eax\n\t"
	//       	"movl	$1, %%ebx\n\t"
	//	"movl	%0, %%ecx\n\t"
	//	"movl	$1, %%edx\n\t"
	//	"int	$0x80\n\t"
	//	:"=m"(chr)	
	//);
}

int main(int argc, char**argv)
{
	char ch = 0x61;
	int i = 0;

	for (i = 0; i < 26; ++i)
	{
		printit(&ch);
		++ch;
	}
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

If this is for linux, why are you using int 21. shouldn't you be using

movl	$4, %eax
movl	$1, %ebx
movl	pointer to whatever you want to print, %ecx
movl	len of what you want to print, %edx
int $0x80
gerard4143 371 Nearly a Posting Maven

Yeah so what's the problem? Try reading the file back into a structure Person like:

struct Person pread;

for( i = 0; i < 2; i++ )
  {
      read(x, (char*)&pread, sizeof(struct Person));
      fprintf(stdout, "name->%s\n", pread.name);
      fprintf(stdout, "address->%s\n", pread.address);
  }

and you'll find your data's all there and intact

gerard4143 371 Nearly a Posting Maven

Nice program....Why did you post it?

gerard4143 371 Nearly a Posting Maven

AHHH! Drat! The first tutorial I ever read was in Intel syntax; so as I say I'm likely to make many mistakes in AT&T syntax. I think, however, that it is probably better to write AT&T -- when you learn it I think it's more explicit -- you can easily see what are variables, what is in hex, and what is being used as a register.

Thank you :)


Linux.

I just figured out why the list of registers didn't work. You're meant to put %% where you use them instead of a singe %; as per this article http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#s5

Do you know if I need ring 0 access to use halt? I would assume so because IIRC it hangs the machine; and obviously you don't want me running code on your machine that halts execution :P

Thanks.

If your going to be messing around with assembly system programming then you should download the Intel or AMD manuals, they have explanations for all the opcodes..

gerard4143 371 Nearly a Posting Maven

Hi,

I'm running the code on 64 bit machine.
i can force compile the C program using the gcc -o -m32.

But do you know how to create a shared object using the ld (linker)so that it creates a 32 bit shared object?

I'm running the ld on a 64 bit Intel Xeon running on SuSE linux.

Thanks!

Just curious, why are you trying to create a 32 bit program for a 64 bit machine?

gerard4143 371 Nearly a Posting Maven

They were both using Python 2.6.2

gerard4143 371 Nearly a Posting Maven

That's because your writing the binary/hex value of the integer and not its ascii text representation...

The best way to read and write a structure is to write the structure all at once i.e.

struct person 
{

};

struct person Person;

write(fd, (char*)&person, sizeof(struct person));
read(fd, (char*)&person), sizeof(struct person));
gerard4143 371 Nearly a Posting Maven

Well Linux has a few - Code::Blocks, Gedit, Kwrite, KDevelope, Gvim and so on. Myself I'm fond of Vim/GVim

jbennet commented: quick reply +36
gerard4143 371 Nearly a Posting Maven

Luckily for you I have nothing to do right now, Sooo I made the appropriate changes, tell me how this works:

#! /usr/bin/python

import Tkinter, threading, time
mylabel=None
global mylabel
class marquee(threading.Thread):
	def run(self):
		while self.looping:
			self.text = mylabel['text'][-1] + mylabel['text'][:-1]
			mylabel['text'] = self.text	
			time.sleep(.2)
class MyLab:
	DATA = 'this is the marquee message! '
	START = 'start marquee'
	STOP = 'stop marquee'
	def __init__(self, master):
		self.looping = 1
		self.frame = Tkinter.Frame(master)
		mylabel = Tkinter.Label(self.frame, text = MyLab.DATA, background = 'white')	
		self.start = Tkinter.Button(self.frame, text = MyLab.START, command = self.startit)	
		
		mylabel.pack()
		self.start.pack()
		self.frame.pack()
		
	def startit(self):
		if (self.start['text'] == MyLab.START):
			self.looping = 1
			self.start['text'] = MyLab.STOP
			tr=marquee()
		else:
			self.looping = 0
			self.start['text'] = MyLab.START
#I moved this function to another class which is threaded.
#	def marquee(self):
#		while self.looping:
#			self.text = mylabel['text'][-1] + mylabel['text'][:-1]
#			mylabel['text'] = self.text	
#			time.sleep(.2)	
		
root = Tkinter.Tk()

mymar = MyLab(root)

root.mainloop()

This solved the Runtime error i got before, it should fix your problem.

The thread doesn't run at all...The question really isn't how to get this running as to why it works on mandriva64 and not slackware 64...I thought Python was platform independent

gerard4143 371 Nearly a Posting Maven

I'm actually writing this code as inline ASM but I feel it is more relevant to ASM than it is to C...

Basically all I want to do for now is print the alphabet. However I'm having some trouble getting used to AT&T syntax (I would rather learn it than keep just using Intel syntax) and I'm also unsure as to how to solve this segfault I'm getting:

#include <stdio.h>

int main() {
    // code
    {
        asm volatile("movb %ah, 0x4C\n" /* BIOS interrupt call for output */
            "movb $'A', %AL\n"          /* Place "A" in AL                */
            "jmp start\n"
            "start:\n\t"
                "add $1, %AL\n\t"   /* Add 1 to 'A' to move on to 'B', etc. */
                "print:\n\t\t"
                    "int $0x21\n\t" /* Print contents of AL */
              #if 0
                "hlt\n"       /* Halt the machine (commented out because I think I need ring 0 access to use hlt) */
              : " %ax", "%bx" /* List of registers used (commented out because GCC complained of the comma)       */
              #endif
            );
    }
    // code
    return 0;
}

I have tried without the "volatile" keyword. I did nothing, as I expected...

Thank you :)

Your seg fault is probably from this line

movb %ah, 0x4C\n

Your moving the contents of ah into memory address 0x4c

Are you writing this for Linux or Windows?

gerard4143 371 Nearly a Posting Maven

Linked list and binary tress use recursion

gerard4143 371 Nearly a Posting Maven

The program I tested at first was a simple client/server program where the server used Tkinter as its graphical front end...this failed. I then tried a very simple threading program and again it failed...here's the code for the simple program..Note the processor is single core

#! /usr/bin/python

import Tkinter, thread, time

class MyLab:
	DATA = 'this is the marquee message! '
	START = 'start marquee'
	STOP = 'stop marquee'
	def __init__(self, master):
		self.looping = 1
		self.frame = Tkinter.Frame(master)
		self.mylabel = Tkinter.Label(self.frame, text = MyLab.DATA, background = 'white')	
		self.start = Tkinter.Button(self.frame, text = MyLab.START, command = self.startit)	
		
		self.mylabel.pack()
		self.start.pack()
		self.frame.pack()
		
	def startit(self):
		if (self.start['text'] == MyLab.START):
			self.looping = 1
			self.start['text'] = MyLab.STOP
			thread.start_new_thread(self.marquee, ())
		else:
			self.looping = 0
			self.start['text'] = MyLab.START	
	
	def marquee(self):
		while self.looping:
			self.text = self.mylabel['text'][-1] + self.mylabel['text'][:-1]
			self.mylabel['text'] = self.text	
			time.sleep(.2)	
		
root = Tkinter.Tk()

mymar = MyLab(root)

root.mainloop()

Note all the code that I've mentioned above worked well on the same box but with Mandriva 64 bit installed on it

gerard4143 371 Nearly a Posting Maven

Not sure what your asking?

Do you mean you want to create:

1. a thread which exists in the current process
2. a new process which exists independently

gerard4143 371 Nearly a Posting Maven

Hi everyone,

I recently installed Slackware 13/x86_64 on one of my boxes and now I'm having troubles with Python code that uses threading and Tkinter. This problem never existed on other Linux distro's, it just appeared with Slackware.

The box in question
Acer Athlon x86_64 single core used to run Mandriva/64 and the Python code worked fine.

Now it runs Slackware13/64 and Python threading and Tkinter are not getting along at all(program crashes with out of stack space infinite loop for the thread).

Has anyone experienced anything like this? Any suggestion?...Gerard4143

gerard4143 371 Nearly a Posting Maven

I'm extremely new to assembly, and I don't even know if this is the source of my problem could you tell be why it always says argument 2 is larger even though its not. And please Don't criticize my code, I'm new and I'm really not in the mood to deal with it.

To answer this question "why is argument 2 larger" its because your comparing pointer values and not the values themselves. Try dereferencing the value(s) on the stack

gerard4143 371 Nearly a Posting Maven

Looks like you mixing i386 and x86_64 code according to you error message "ld: warning: i386 architecture of input file `chglobals.o' is incompatible with i386:x86-64 output"

Here's a simple makefile to create a shared object and use a shared object...Hope it helps

test: getsetx.so test.o
  gcc test.o -o test -ldl

test.c: test.o
  gcc -c test.c

getsetx.os: getsetx.o
  ld -shared -o getsetx.so getsetx.o

getsetx.o: getsetx.c
  gcc -fPIC -c getsetx.c
gerard4143 371 Nearly a Posting Maven

What does this term mean "getting garbages"?

gerard4143 371 Nearly a Posting Maven

I have to run right now but try this code...will it print the first argument "one" when you run it like <filename> one

.section .data

.section .bss

.section .text
	global _start
_start:
  pop ecx
  pop ecx

  mov eax,4
  mov ebx,1
  mov edx,3
  int 80h

  mov eax, 1
  mov ebx, 0
  int 80h

My apologizes if it doesn't work, I don't use nasm

gerard4143 371 Nearly a Posting Maven

Well your heading in the right direction, maybe a little ahead of yourself right now. Can you pop off a string pointer value from the stack and display it using the write system call?

gerard4143 371 Nearly a Posting Maven

Right away I have to ask, are you popping the program's arguments off the stack? If you are then the values are pointers to strings and not the the strings themselves

gerard4143 371 Nearly a Posting Maven

So when I take an argument off the stack it seems that is in the form of a string, is there a way i can convert it to a integer so i can "cmp" it with another argument which i also wish to convert to an int? I am a newbie to ASM but i do realize this isn't going to be as easy as it is in higher level languages. Any help?

Could we see the code please...As for values(strings) on the stack well I guess that depends on what was pushed onto the stack...

gerard4143 371 Nearly a Posting Maven

If your going that route I would check the sizeof(argc) just to see what your dealing with, .i.e is it an unsigned char, unsigned short or whatever

Just to see what size of variables are accepted

gerard4143 371 Nearly a Posting Maven

This works..maybe you can figure out why

#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<unistd.h>
#include<string.h>

struct Student
{
  char name[21];
  char id[11];
  char DOB[9];
  char gender[2];
  char status[2];
};

struct Student myArr[5];//An array of Struct Student  
int main()
{
  int x, y, z;
	char dumb[1];
  char newline[2] = { "\n" };
  char sep[5] = { "    " };
  char buf1[] = { "Please enter the name of the student's:" };
  char buf2[] = { "Please enter the student's id:" };
  char buf3[] = { "Please enter the student's DOB:" };
  char buf4[] = { "Please enter the student's gender:" };
  char buf5[] = { "Please enter the student's marital status:" };

  //O_CREAT requires a third argument the mode which specifies the access permission bits
  //S_IRWXU indicates that the user has read, write and execute permissions
  x = open( "/home/user/Desktop/Labsheets/Labsheet4/input.dat", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU );
  //fd 0 is standard input and 1 is standard output
  //will read from standard input and place data in the buffer
  //read return number of bytes read
  int i;
  for( i = 0; i < 5; i++ )
  {
    write( 1, buf1, strlen(buf1) );
    read( 0, myArr[i].name, 20 );//read from standard input and place data in buffer
    write( 1, buf2, strlen(buf2) );;
    read( 0, myArr[i].id, 10 );
    write( 1, buf3, strlen(buf3) );
    read( 0, myArr[i].DOB, 9 );
    write( 1, buf4, strlen(buf4) );
    read( 0, myArr[i].gender, 1 );
	read( 0, dumb, 1 );
    write( 1, buf5, strlen(buf5) );
    read( 0, myArr[i].status, 1 ); …
gerard4143 371 Nearly a Posting Maven

Why do you insist on redefining functions...Try this

#include <stdio.h>

void  memseta(void *dest,int val,int cnt)
{ 	
	while(cnt--)
	{
		*((char *)dest++) = (char)val;
		
	}
}
int main()
{
	char arr[]={1,2,3,4,0};
	memseta(arr,103,4);
	printf("%s\n",arr);
	
	return 0;
}
gerard4143 371 Nearly a Posting Maven

You really should post this on the networking section

gerard4143 371 Nearly a Posting Maven

Dumb question - do the character pointers in this structure receive memory references or do you expect them to be created by the message queue in the receive funtion?

struct test
{
	int a;
	char *b;
	char *c;
};
gerard4143 371 Nearly a Posting Maven

I'm extremely new to assembly and was wondering if there is a speed difference between 16, 32, and 64bit registers.

Not sure what you mean by faster...

64 bit register/CPU's are faster yes because they can transfer more data plus the CPU has twice as many general registers so a 64 bit CPU(Inte/AMD) has 4 times the general register space(as compared to 32 bit Intel/AMD) to work with. So is it faster? Yes.

Or do you mean can the instruction preform faster if your working with the smaller 16 and 32 bit registers? This I'm not sure of but I do know if you opt for the smaller registers the result program will be smaller hence more efficient...

Hope this helps

Also the 8/16/32and 64 bit register are just the same register. The small versions are just fractions of the larger i.e.

al, ah, ea, eax, rax are the same register

gerard4143 371 Nearly a Posting Maven

Tell me how can a compiler calculate the strlen if it does not know what the string is.You are inputting the string at runtime ie out of compiler's reach.To optimze the code it need a string constant.. something at compile time.

Cheers!!

This I don't know for certain but I do know that the object dumps support the compiler calculating the value and is this so hard to conceive - we use strlen all the time maybe they(gcc) decide to allow optimization on this function since its used frequently and its value is just the len of a string - so when we substitute our own strlen function(one that doesn't return a standard string length) we can get inconsistent values....I know this sounds pretty far out but everything thing I've seen points to the compiler optimizing the function call away...

gerard4143 371 Nearly a Posting Maven

did you try putting the full path with your cd

gerard4143 371 Nearly a Posting Maven

Here's some code that can't optimize away the function call

#include <stdio.h>

size_t strlen(const char *s);

int ans = 0;

int main(int argc, char**argv)
{
	char ch[20];
	fputs("enter a string->", stdout);
	fgets(ch, 19, stdin);
	return ans = strlen(ch);
}

size_t strlen(const char *s)
{
	int i = 0;
	
	while (*s++)
		++i;
		return i + 10;
}

I all have to say is..Why does this one work as intended if its the linker or some other mysterious thing at work...Shouldn't it return the normal strlen result instead of the one I defined here...It doesn't the one I defined works fine in this situation because the compiler can't optimize the function call away...

gerard4143 371 Nearly a Posting Maven

Hello guys, I'm trying to make this work

all: daemon client

daemon:	
	cd ./daemon; make daemon
client: 
	echo going in
	cd ./client; make client
clean:
	cd ./daemon ; make clean
	cd ./client ; make clean

But I'm having 2 problems:
1) Make ALWAYS tells me there's nothing to be done. Wether I try to make daemon, client or all. The echo command doesn't even seem to work.
Edit: turns out I can't use the command "make daemon" on both the main makefile and the secondary makefile.


2) Clean DOES work but it doesn't clean the client if cleaning the daemon failed.

So you have makefiles in the ./client and ./daemon
directories?

Plus I've always seem makefiles like

all: daemon client

daemon:	
	cd ./daemon
	make daemon
client: 
	echo going in
	cd ./client
	make client
clean:
	cd ./daemon
	make clean
	cd ./client
	make clean
gerard4143 371 Nearly a Posting Maven

Here's some code that can't optimize away the function call

#include <stdio.h>

size_t strlen(const char *s);

int ans = 0;

int main(int argc, char**argv)
{
	char ch[20];
	fputs("enter a string->", stdout);
	fgets(ch, 19, stdin);
	return ans = strlen(ch);
}

size_t strlen(const char *s)
{
	int i = 0;
	
	while (*s++)
		++i;
		return i + 10;
}
gerard4143 371 Nearly a Posting Maven

Yes the trick works.

yes behaving same on my side.
This is coz strlen is getting linked statically ..not only static linking but also the code is inlined by the linker as the function is too small.
Compiler is not doing the calculation,it's the linker.
But still I am not sure ... I think the glibc is the standard C library in Linux... All the C standard library functions are in it .So that is supposed to be linked dynamically by default which is the default behavior of gcc.
Like it always link printf dynamically.
In that case this can be assumed that this is the linker's decision which function should be linked statically and inlined or dynamically.
Coz if linker has to make something inline that function has to be statically linked(here strlen)..but codes cannot be patched(or made inline) at runtime ie by a loader.Loader can do only address patching.
At this point of time this is my assumption only.
I might be wrong.

Cheers!!

My understanding is - linkers handle address resolution and compilers generate efficient code by optimizing where possible i.e. reducing a redundant or constant calculations to a fixed value...

gerard4143 371 Nearly a Posting Maven

This will call the function with a little trickery

#include <stdio.h>

typedef size_t(*pfunc)(const char*);

size_t strlen(const char *s);

int ans = 0;

int main(int argc, char**argv)
{
	pfunc tfunc = (pfunc)strlen;
	return ans = tfunc("gerard");
}

size_t strlen(const char *s)
{
	int i = 0;
	
	while (*s++)
		++i;
		return i + 10;
}

exe now returns 16 to operating system bypassing the compiler generated value

gerard4143 371 Nearly a Posting Maven

O yes I did but need some time to sort out coz gas syntaxes are alien to me I am more familiar with masm .
Meanwhile if you can make out something please do post.
Cheers!!

Did look at the prev post

gerard4143 371 Nearly a Posting Maven

Found something interesting

#include <stdio.h>

size_t strlen(const char *s);

int ans = 0;

int main(int argc, char**argv)
{
	return ans = strlen("gerard");
}

size_t strlen(const char *s)
{
	int i = 0;
	
	while (*s++)
		++i;
		return i + 10;
}
000000000040048c <main>:
  40048c:	55                   	push   %rbp
  40048d:	48 89 e5             	mov    %rsp,%rbp
  400490:	89 7d fc             	mov    %edi,-0x4(%rbp)
  400493:	48 89 75 f0          	mov    %rsi,-0x10(%rbp)
  400497:	c7 05 0f 04 20 00 06 	movl   $0x6,0x20040f(%rip)        # 6008b0 <ans>
  40049e:	00 00 00 
  4004a1:	8b 05 09 04 20 00    	mov    0x200409(%rip),%eax        # 6008b0 <ans>
  4004a7:	c9                   	leaveq 
  4004a8:	c3                   	retq

Found something interesting in the object dump...The compiler is calculating the strlen an placing the value directly into my global variable ans

The line

400497: c7 05 0f 04 20 00 06 movl $0x6,0x20040f(%rip) # 6008b0 <ans>

is proof that there is no function call at all just a compiler computed value is dumped into ans....Can you verify this on your end