C & C++ question

Status
Not open for further replies.

n2casey

Super Hero - Super Powers
Codes which can b executed in C++ can't b executed in C but is there any code in C which can't b executed in C++??????
 

Pathik

Google Bot
afaik all c codes work in c++ ...
but wats the use... c++ codes codes give u added functionality...
 

aceman

Broken In
AFAIK,Printf and scanf are supported in C++...........all my drivers are in C++ but I use printf to display the output.

piyush619 said:
Also i m not too sure but dos.h and direct memory access will not work in C++

Direct Memory Access ( DMA ) will work in c++, it will work in C and heck it can even work in asm.I am not very sure what you meant in the above statement, could you please elaborate ?

This how I use DMA

from a code called as dma.cpp

// Allocate an adapter object on the stack
DMA_ADAPTER_OBJECT AdapterObject;
AdapterObject.ObjectSize = sizeof(AdapterObject);
AdapterObject.InterfaceType = Local;
AdapterObject.BusNumber = 0;

// Allocate a single paged 4 KB output buffer
dma_out_page[0] = (PUCHAR) HalAllocateCommonBuffer(&AdapterObject, dma_buffer_size * VIDEO_DMA_BUFFERS, &dma_out_logical_address, FALSE);

if (!dma_out_page[0]) {
ERRMSG(": DMA Buffer Page Allocation Failed");
return FALSE;
}

pathiks said:
afaik all c codes work in c++ ...
but wats the use... c++ codes codes give u added functionality...
C++ introduces high overhead, C is still very popular in my segment ( Embedded Systems) and all my bootloader and HAL (hardware abstraction layer) is coded in a mix of asm and C.
 

piyush gupta

Cyborg Agent
aceman said:
AFAIK,Printf and scanf are supported in C++...........all my drivers are in C++ but I use printf to display the output.

printf() and scanf() are defined in <stdio.h> u need to include this file and it is only available with C Compiler.
today mostly compilers comes for C and C++ both
try only C or only C++ compliler


aceman said:
Direct Memory Access ( DMA ) will work in c++, it will work in C and heck it can even work in asm.I am not very sure what you meant in the above statement, could you please elaborate ?
This how I use DMA

I m not talking about DMA structure
i dont know about Embedded Systems
i m talking about
Display Adapter Address
e.g
using long far pointer in C we can access video memory addresses using itt86() function
 

aceman

Broken In
piyush619 said:
printf() and scanf() are defined in <stdio.h> u need to include this file and it is only available with C Compiler.
today mostly compilers comes for C and C++ both
try only C or only C++ compliler
Actually these header files are loaded by deafult by the compiler, but I do accept my compiler compiles both C and C++.

piyush619 said:
I m not talking about DMA structure
i dont know about Embedded Systems
i m talking about
Display Adapter Address
e.g
using long far pointer in C we can access video memory addresses using itt86() function

No more clarification is that a int86() function or itt86() ? ie You want to access some portion of memory directly by using a pointer.

If I get it right, you meant "Directly accessing the Memory" and Not "Direct Memory Access (DMA)" like a passing a pointer and using that accessing the memory area ?
if this is the requirment then it is very much possible in C++ by using the code snippet as follows.This reserves a protion of video memory and can be accessed by using that pointer

from somevideodriver.cpp

BYTE gFrameBuffer;

gFrameBuffer = (PBYTE)VirtualAlloc(NULL,size,MEM_RESERVE,PAGE_NOACCESS);

VirtualCopy(gFrameBuffer,pVirtAddr,size,PAGE_READWRITE|PAGE_NOCACHE);

or a More down to earth Implementation

BYTE *gFrameBuffer;

gFrameBuffer= (BYTE *) MmMapIoSpace(
<<PHYSICAL_ADDRESS>> 0x80000,
<<NumberOfBytes>> 1024*1024,
<<CacheEnable>> FALSE
);
Best of my knowledge only some typecasting is required for c++, whereas I can get away without that in C.Otherwise pointers should behave more or less the same in both.
I beileve accessing memory directly has more to do with OS permissions than with any limitations in C or C++.
 
Last edited:

piyush gupta

Cyborg Agent
aceman said:
Actually these header files are loaded by deafult by the compiler, but I do accept my compiler compiles both C and C++.

see there are functions defined in header file <stdio.h>
if u dont know read any C book

aceman said:
No more clarification is that a int86() function or itt86() ? ie You want to access some portion of memory directly by using a pointer.
If I get it right, you meant "Directly accessing the Memory" and Not "Direct Memory Access (DMA)" like a passing a pointer and using that accessing the memory area ?

i means that sorry for mistyping
its int86()

aceman said:
if this is the requirment then it is very much possible in C++ by using the code snippet as follows.This reserves a protion of video memory and can be accessed by using that pointer

but in C u can do it by directly assign it using Octal and hexadecimal memory address to long far pointers

Read Writing TSR by YPK


aceman said:
Best of my knowledge only some typecasting is required for c++, whereas I can get away without that in C.Otherwise pointers should behave more or less the same in both.

no there is a big difference in pointer behaviour in C and C++

read Understand Pointers in C by YPK
Let Us C++ by YPK

aceman said:
I beileve accessing memory directly has more to do with OS permissions than with any limitations in C or C++.
no OS permission is required

see same code works on Linux and Windows
In C it works on address of Video memory where is OS there
u can use same code for DOS,Windows,Linux
 

aceman

Broken In
piyush619 said:
see there are functions defined in header file <stdio.h>
if u dont know read any C book ..................
lol.........you are just too childish....I never accused you of anything.....we were just having a healthy debate...b/w I am a device driver developer with TI with about 4+ years experence and TI generally takes people who do do not know whats is stdio.h :) :) .Stop using deragatory terms like "if u dont know read any C book " ........I am your daddy when it comes to C/C++.I had even written portions of a cross compiler for a new architecture.
and yes I have met YPK in a microsoft embedded seminar where I highlated to him that he must broaden his C/C++ books to focus on architectures like ARM where there is no FAR pointer,No use for int86...etc.

anyway before i reply to your previous mail, i need some further clarification from you...

a)Have you worked on any device drivers before?

b)Do you know what is physical and virtual memory ?.
No pointer running in the desktop is a direct memory access since you are running in logical address space.

c)How can you access some physical memory region when you are running in virtual memory space ?

d)What do you mean by direct memory access ? My undestanding is like this.
You have a physical address in let us say 0x400 where you have a LED and you wish to toggle this LED by an application by writing 0x01 to this address.
Now when running on Windows Xp/XP embedded/Point of Service/Wince/Linux...etc how can you make this happen without OS permissions ?

e)Lot of what you speak is highly architecture specifc ( aka X86) and is in no way a limitation on any language

f)Tell me one difference ( with a code snippet ) where a pointer in C , behaves differently in C++.

Best of my knowledge ( not sure about YPK) there was nothing called as Near and FAR pointers.These were just extensions to the language to support some Arcane Architectures (read x86) and such makes no sense to much of the architectures I work with like ARM,Power Pc,MIPS...etc.
 

piyush gupta

Cyborg Agent
^^ there are Near and Far Pointers
in c
i read it in Understanding Pointers in C

I dont know much detail about them

Also Dont use terms like u r too big even if u have experience of 4+ years

how much u know about Siebel and CRm interfaces

these all are metters of fields in which we all work and nothing else

i too just wanna healthy debate and nothing much much


I know about physical and virtual memories
have u read TSR using pointers by YPK

there he uses device memory address and write some code about it

i dont remmeber it coz i read C and C++ 3-4Years Ago

anyhow nice talking to u

no more stuffs from my side as u know too much than me
still one thing as much i know wihtout stdio.h code shows u error for"Prototype of printf fucntion"
 

gopi_vbboy

Cyborg Agent
n2casey said:
Codes which can b executed in C++ can't b executed in C but is there any code in C which can't b executed in C++??????

C is a subset of C++.Everty aspect of C should supported in C++.There is no qestion of not supporting
 
OP
n2casey

n2casey

Super Hero - Super Powers
Sorry for late reply but these days I can't acess net regularly.
I have asked that question coz that question was asked in an interview & I want to know the answer so that I can answer it net time (if asked).
 
Status
Not open for further replies.
Top Bottom