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

Passing para meter in the c and c++ functions

hi,


I am passing a parameter as poineter in my prtotype but in the definition i am passing as reference. i am getting the warning prototype not defined.Why

Ex:
Expand|Select|Wrap|Line Numbers
  1. short x(byte a, short* y)//prototype of the c function
  2.  
  3. //Definition is 
  4. short x(byet a, short & y)
  5. {
  6.     classname::x(a,y);//member function means c++ function
  7. }
  8.  
Jul 20 '07 #1
2 1274
Banfa
9,065 Expert Mod 8TB
I am passing a parameter as poineter in my prtotype but in the definition i am passing as reference. i am getting the warning prototype not defined.Why
Hi nabakishorebehera,

please make sure you use [code=cpp]...[/code] tags round your code when you post it.

Well that is because C++ supports function overloading, you have not provided the prototype for the function you have defined (that uses a reference) but you have provided a prototype for a function you have not defined.

The prototype and the definition must be exactly the same with the sole exception that in C++ (not in C) the prototype may provide default values for arguments which must not appear in the definition.


Are you trying to create a function in a CPP file that can be called from C? A fairly common technique.

To do this
  1. The prototype MUST match the definition
  2. Where you have the prototype in the header you must mark it as a function that uses the C naming convention, that is that does not perform then name mangling that C++ introduces to facilitate function overloading. The normal method of doing this is to inlude this code in the header file
    Expand|Select|Wrap|Line Numbers
    1. #ifdef  __cplusplus
    2. extern "C" {
    3. #endif
    4.  
    5. // Prototypes for functions using C calling convention here
    6.  
    7. #ifdef  __cplusplus
    8. }
    9. #endif
    10.  

You will then be able to call the function from C or C++, the function itself may reside in a C or CPP file, if it does reside in a CPP file then even though it has C naming convention you will be able to use C++ in the body of the function, thus allowing C code to make calls into C++ code.
Jul 20 '07 #2
gpraghuram
1,275 Expert 1GB
hi,


I am passing a parameter as poineter in my prtotype but in the definition i am passing as reference. i am getting the warning prototype not defined.Why

Ex:
Expand|Select|Wrap|Line Numbers
  1. short x(byte a, short* y)//prototype of the c function
  2.  
  3. //Definition is 
  4. short x(byet a, short & y)
  5. {
  6.     classname::x(a,y);//member function means c++ function
  7. }
  8.  
The function declaration and definition is not matching and thats why u are getting the error.
In C++ this becomes overloading

Raghuram
Jul 20 '07 #3

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

Similar topics

0
by: Oscar22pr | last post by:
QUIERES GANAR DINERO PARA PAGAR TUS DEUDAS??? GASTE 5 MINUTOS DE SU VIDA EN LEER ESTO Y VERA QUE REALMENTE FUNCIONA. LEGALMENTE!!!!!! !!!IMPRIME ESTA HOJA ...YAAAAAAAAAAA!!! Permíteme empezar...
3
by: Brian Birtle | last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible to build a file upload progress meter using ASP.NET" **** First person to prove me wrong gets "All Time .NET Programming GOD"...
1
by: Doug | last post by:
In I.E. 6 (and probably other versions as well), there is a sort of progress meter in the panel at the bottom of the window. This meter increments a few pixels at a time when the browser is trying...
1
by: SatishPasala | last post by:
hi I have like three aspx pages. Each page has a few check boxes. So depending on the selection of the check boxes the meter which is a semi circle with a pointer .(I have to build the...
0
by: risomarmarques | last post by:
Agora todos os seus sonhos se realizarão! VOCÊ JÁ IMAGINOU GANHAR R$ 30.000,00 EM MENOS DE 4 SEMANAS INVESTINDO APENAS R$ 6,00 - Valor único - não mensal? ACHA IMPOSSÍVEL?? ENTÃO LEIA ESTE...
1
by: David Roza | last post by:
Groups Home | Help | Sign in Web Images Groups News Froogle Maps more » Advanced Groups Search
23
ADezii
by: ADezii | last post by:
Many Access Users fail to realize that it has a built-in Progress Meter that can display the relative completion percentage of various processes. It is fairly limited, but nonetheless, does provide...
2
by: DarthPeePee | last post by:
Hello everyone. I am working on a Password Strength Meter and I am running into 1 problem that I would like to fix. When pressing the "Clear Password & Try Again" button, the password clears...
0
by: Ranger | last post by:
TRANSFORME R$12,00 EM R$12.000,00 SÓ VAI TOMAR UM POUCO DO SEU TEMPO E VC Ñ VAI SE ARREPENDER ACREDITE!!! LEIA COM ATENÇÃO. MÉTODO APROVADO PELA REVISTA EXAME Você já imaginou ganhar até R$...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.