Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. common var for C and C++

common var for C and C++

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    meirav
    wrote on last edited by
    #1

    I have 2 fils in a project : 1 Cpp file and the second C file . a variable x is declared in the Cpp file and i need that the C file will "know" that variable. is there supose to be a problem? when i tried this: Cpp File C_File int x; extern int x i get an error : unresolved external I will be very glad to get any help :omg:

    J N 2 Replies Last reply
    0
    • M meirav

      I have 2 fils in a project : 1 Cpp file and the second C file . a variable x is declared in the Cpp file and i need that the C file will "know" that variable. is there supose to be a problem? when i tried this: Cpp File C_File int x; extern int x i get an error : unresolved external I will be very glad to get any help :omg:

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      Put this in your .h:

      #ifdef __cplusplus
      extern "C" {
      #endif
      extern int x;
      #ifdef __cplusplus
      }
      #endif

      and this in your .cpp:

      #include <···.h>
      int x;

      Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      1 Reply Last reply
      0
      • M meirav

        I have 2 fils in a project : 1 Cpp file and the second C file . a variable x is declared in the Cpp file and i need that the C file will "know" that variable. is there supose to be a problem? when i tried this: Cpp File C_File int x; extern int x i get an error : unresolved external I will be very glad to get any help :omg:

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        meirav wrote: int x; extern int x hmmmm... dont put both in the same file. file1.cpp -> declare it there :- int x; file2.c -> extern "C" int x; Try that. Nish Sonork ID 100.9786 voidmain www.busterboy.org Nish is a BIG fan of Goran Ivanisevic

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups