  We investigate the formation of carbon stars as a function of the stellar
mass and parent metallicity. Theoretical modelling is based on an improved
scheme for treating the third dredge-up in synthetic calculations of thermally
pulsing asymptotic giant branch (TP-AGB) stars. In this approach, the usual
criterion (based on a constant minimum core mass for the occurrence of
dredge-up, M_c^min) is replaced by one on the minimum temperature at the base
of the convective envelope, T_b^dred, at the stage of the post-flash luminosity
maximum. Envelope integrations then allow determination of M_c^min as a
function of stellar mass, metallicity, and pulse strength (see Wood 1981), thus
inferring if and when dredge-up first occurs. Moreover, the final possible shut
down of the process is predicted. Extensive grids of TP-AGB models were
computed using this scheme. We present and discuss the calibration of the two
dredge-up parameters (lambda and T_b^dred) aimed at reproducing the carbon star
luminosity function (CSLF) in the LMC. It turns out that the faint tail is
almost insensitive to the history of star formation rate (SFR) in the parent
galaxy (it is essentially determined by T_b^dred), in contrast to the bright
wing which may be more affected by the details of the recent SFR. Once the
faint end is reproduced, the peak location is a stringent calibrator of lambda.
The best fit to the observed CSLF in the LMC is obtained with Z=0.008,
lambda=0.50, log(T_b^dred)=6.4, and a constant SFR up to 5x10^8 yr ago. A good
fit to the CSLF in the SMC is then easily derived from the Z=0.004 models, with
a single choice of parameters, and a constant SFR over the entire significant
age interval. The results are consistent with the theoretical expectation that
the third dredge-up is more efficient at lower Zs.
