473,396 Members | 2,158 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,396 software developers and data experts.

OK .. So we think we know how to run a program.

Hey, I just ported one of my programs from gcc to turbo c compiler, and noted a strange thing. I used a structure

struct s
{
int a;
char b;
}obj;

on gcc, sizeof(obj) gave 8, (4 for int, 1+3 for char due to padding);
while on turbo c, sizeof(obj) gave plain 3 (2 for int, 1 for char).

Now I took the value of a to fit into two bytes, and the program seemed to show same results with both compilers.

Now my question is : 1) Is the same machine code generated for both compilers.
2) If not, which is a faster version (as far as number of machine cycles are concerned).
Jul 16 '07 #1
3 1085
JosAH
11,448 Expert 8TB
1) Is the same machine code generated for both compilers.
Not likely; one compiler decided an int to be two bytes, another wants an int
to be four bytes.

2) If not, which is a faster version (as far as number of machine cycles are concerned).
Who can tell? It depends on the processor and on the instructions generated
by the compilers.

kind regards,

Jos
Jul 16 '07 #2
Hmm Ok, I think I need some more explanations. Ok Let's go step by step

1) Let's say we are using the gcc compiler, and a Pentium 4. Also say there is another machine running same gcc compiler, but a different processor, say Sunsparc. So, now, even though only the processor differs, yet different machine codes will be generated for the same code. (I assume it to be the case, kindly correct me I am wrong..)

Now how does the compiler know that what machine code to generate. (I presume it has got to do something with compiler "Adjusting" its parameters, during boot up time, BUT I AM NOT SURE... PLZ help..)

Looking forward to a reply.

Ajay Garg
Jul 17 '07 #3
JosAH
11,448 Expert 8TB
Hmm Ok, I think I need some more explanations. Ok Let's go step by step

1) Let's say we are using the gcc compiler, and a Pentium 4. Also say there is another machine running same gcc compiler, but a different processor, say Sunsparc. So, now, even though only the processor differs, yet different machine codes will be generated for the same code. (I assume it to be the case, kindly correct me I am wrong..)

Now how does the compiler know that what machine code to generate. (I presume it has got to do something with compiler "Adjusting" its parameters, during boot up time, BUT I AM NOT SURE... PLZ help..)

Looking forward to a reply.

Ajay Garg
The compiler itself is a (compiled) binary. You can't run a gcc for a Sparc on
a pentium, nor vice versa. See your other thread where I also explained things
a bit more. The compiler doesn't 'know' anything about other processors. It's
the code generating part of the compiler that knows all about one single processor.

kind regards,

Jos
Jul 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

41
by: John Marshall | last post by:
How about the following, which I am almost positive has not been suggested: ----- class Klass: def __init__(self, name): self.name = name deco meth0: staticmethod def meth0(x):
9
by: Carlos | last post by:
I'm responsible for the content in a call center's intranet site. There are approximately 600 pages on 7 sub-webs. I have access to the sub-webs, but I don't have access to the root web or web...
50
by: jbailo | last post by:
Subject: dotnet is a farce. You know, I was always impressed with the way one could write a http program with c# or java. To me, it showed how 'superior' these languages are because they made...
1
by: Qin Chen | last post by:
I will present very long code, hope someone will read it all, and teach me something like tom_usenet. This question comes to me when i read <<Think in C++>> 2nd, chapter 10 , name control,...
9
by: John Cho | last post by:
// CHO, JOHN #include<iostream> class fracpri{ int whole; int numer; int denom;
9
by: Peter Oliphant | last post by:
For some reson my code is generating a LNK1215 error, which 'suggests' I re-install VS C++. So I did. which did NOT solve the problem. The weid part is it seems to be caused by my one CPP file, but...
5
by: garyusenet | last post by:
At least I think it's using an API (i don't totally understand the concept.) I'm using Act 6. I need to interface with the act database and add 'contacts' to the database. The reason I need to...
1
by: Tannie | last post by:
:confused: Well, I'm not really sure what I'm using. All I know is its some freeware program, most probably C++, and it involves cygwin and Notepad2 and this java compiler. Anyway, I'm having...
0
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into...
0
by: danbst | last post by:
There are script languages compiled at runtime. So, we can download interpreter and code-file to run the program. Everybody knows it. here is my idea. I create redistributable package (for *nix...
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:
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.