4507

Undeclared identifier but is declared

I wrote this code :

#define HIDE __attribute__((visibility("hidden"))) HIDE int main(){ int x = 10; int z = 5; int c; c = call1(x,z); } HIDE int call1(int a,int b) { int r; r = a+b; return r; }

But when I try to compile it I get this error: error: use of undeclared identifier 'call1' c=call1(x,z);

I already looked here but have not found similar problems. If it does matters, I am using Xcode to compile the code.

Answer1:

Undeclared identifier but is declared

No, it isn't. Your identifier is defined, not declared. This is a common source of confusion. Declaration of an identifier means to give it a unique signature that can be referred to in the following code lines. Definition means to give it a certain value/implementation. A definition implies declaration for the following code.

<strong>At least an identifiers complete declaration must have been seen before first usage.</strong>

That said you can simply put a declaration for your function before main()

HIDE int call1(int a,int b);

or just change your code to

HIDE int call1(int a,int b) { int r; r= a+b; return r; } HIDE int main() { int x = 10; int z = 5; int c; c=call1(x,z); }

and put the definition (which actually implies the declaration) before main() to have a forward declaration for your function.

I'm going to cite the current standards section 3.1 here

3.1 Declarations and definitions [basic.def]

1 A declaration (Clause 7) may introduce one or more names into a translation unit or redeclare names introduced by previous declarations. If so, the declaration specifies the interpretation and attributes of these names. A declaration may also have effects including: — a static assertion (Clause 7), — controlling template instantiation (14.7.2), — use of attributes (Clause 7), and — nothing (in the case of an empty-declaration).

...

Recommend

  • Minimize form in Firemonkey application
  • Tradingview Pine script save close price at time of strategy entry
  • How SecureRandom.getInstance() is working in Java
  • Nunmpy sum() function + comprehensions: int32 or in64?
  • regex: Match at least two search terms
  • CSS transition glitch
  • Excel passing a range into a function
  • What is the likely cause of a net::ERR_CONNECTION_ABORTED when uploading a file to Spring
  • Can't compile Arduino CapSense example
  • SPARQL date range
  • Ruby 1.8.6 Array#uniq not removing duplicate hashes
  • Swift Initialization Rule Confusion
  • can variables be set randomly when declaring them again?
  • Get a trait object reference from a vector
  • Less Conflicting Session Manager for Zope 2
  • Xmonad multiple submap key combos
  • What Makes These Two Array Adds Different?
  • php script is parsing content from RTE (tt_news) but internal links are not appearing as speaking ur
  • How can I mock ui-router's resolve values when testing a state's configuration?
  • cordova is not defined - cordova.js has already been loaded :: Ionic
  • NUnit 3.0 TestCase const custom object arguments
  • Subclassing QGraphicsItem prevents me from being able to use itemAt() on a QGraphicsScene/View
  • Does Mobilefirst provide a provision to access web services directly?
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • one Local Olampyad Questions on Informatic in 2011
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • Installing Hadoop, Java Exception about illegal characters at index 7?
  • Nant, Vault & Windows Integrated Authentication
  • Different response to non-authenticated users and AJAX calls
  • Counter field in MS Access, how to generate?
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Javascript + PHP Encryption with pidCrypt
  • When should I choose bucket sort over other sorting algorithms?
  • Websockets service method fails during R startup
  • How do you troubleshoot character encoding problems?
  • KeystoneJS: Relationships in Admin UI not updating
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Understanding cpu registers
  • How to Embed XSL into XML
  • Net Present Value in Excel for Grouped Recurring CF